Component-level art direction with CSS Container Queries
Sara Soueidan · 2021年5月9日
AI 摘要 AI 生成,可能有误
The article explores how CSS Container Queries can be used for component-level art direction, allowing images to adapt their aspect ratio and cropping based on the size of their container rather than the viewport. Using object-fit and aspect-ratio, images can flexibly fit components, but true art direction (swapping entirely different images) requires the element, which currently only responds to viewport-based media queries. The author advocates for Container Queries support in HTML so semantic images inside components can respond to their container's size, noting that for now this is only possible with non-semantic background images in CSS.
Container Queries (CQ) allow us to change the styles of a component so it responds to the size of its nearest container. With CQ, we can change how an element looks based on where on a page it is placed and how much horizontal space it occupies.
A lot about a design pattern could change based on how much space it’s got. So Container Queries can be used to do more than just shift elements around in a layout. (Have you seenJhey’s demo yet?!) But we can only take full advantage of the potential Container Queries offer us if we can use them everywhere a typical viewport media query can be used.
Now that we got Container Queries in CSS, I want them in HTML, too. More specifically, I can see them coming in more handy if they were available in HTML to change an image’s source inside <picture>, just like viewport-based media queries currently are. This would enable us to art-direct images instead of cropping them to fit in a layout.
继续阅读全文
为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。
AI 摘要This article examines the CSS caret-* properties (caret-color, caret-animation, and caret-shape) and the accessibility considerations surrounding the caret, an often-overlooked focus indicator for editable text and caret browsing mode. It explains how caret browsing enables precise keyboard navigation of web pages, and how operating systems like macOS and Windows provide accessibility settings for caret blinking, thickness, and visibility that browsers honor inconsistently. The author urges caution when applying custom caret styles, since the caret may be the only focus indicator some keyboard or pointer users receive.
AI 摘要The author shares their ranked picks for Interop 2027, a yearly project aiming to improve cross-browser interoperability of key web platform features, using Firefox's community ranking page. Their top choices—the HTML focusgroup attribute and the ariaNotify() API—reflect their preference for features that improve both accessibility/user experience and developer experience, followed by other picks like heading-related HTML attributes, Interest Invokers, and various CSS properties. The author notes that features cannot be downvoted, only ranked or left unranked, and concludes by linking to blog posts where other web developers shared their own rankings.
AI 摘要The article explains how CSS-generated content inserted via ::before and ::after pseudo-elements is included in an element's accessible name computation, and why meaningful CSS images, icons, and unicode characters need descriptive alternative text while decorative ones should be hidden from screen readers. It introduces the CSS Generated Content Module Level 3 syntax that lets authors provide alternative text after a slash in the content property (with empty-string alt text for decorative content), noting that browser support is now very good except for older browsers like Internet Explorer. The author shares testing results across browsers and screen readers such as VoiceOver, observing that CSS images without alt text are excluded from the accessibility tree, images with alt text are announced properly, and there are some quirks like NVDA not announcing Chrome's CSS image alt text and Safari only showing broken CSS image alt text when VoiceOver is enabled.
AI 摘要The author and Kevin Powell finally recorded a nearly two-hour video podcast about navigating the world of web accessibility, covering topics like HTML semantics, ARIA, screen readers, the accessibility tree, how CSS affects accessibility, and the author's Practical Accessibility course. They also chatted about shared personal interests such as cooking, fermentation, and nutrition. The author invites front-end designers and developers curious about accessibility to watch or listen and share their feedback.
AI 摘要The article explains how to create a CSS-only scrollspy effect using the new scroll-target-group property combined with the :target-current pseudo-class, which automatically highlights navigation links (like a table of contents) when their target sections are scrolled into view—no JavaScript required. It describes how applying scroll-target-group to a container of HTML anchors promotes them to scroll markers, letting the browser determine and style the active link. The author also covers accessibility considerations, including WCAG contrast requirements for active link styling and using aria-current to convey the active state to screen reader users.