3

Container Queries Explainer & Proposal

 3 years ago
source link: https://www.miriamsuzanne.com/2021/05/02/container-queries/?ref=sidebar
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Container Queries Explainer & ProposalMain content

  • colors

  • type

Search

Container Queries Explainer & Proposal

A path forward, with single-axis containment @ CSSWG

container-query.jpg

May 2, 2021

in

writing, elsewhere, code, w3c, google

Media-queries allow an author to make style changes based on the overall viewport dimensions – but in many cases, authors would prefer styling modular components based on their context within a layout.

My proposal builds on David Baron’s @container proposal, which works by applying size & layout containment to the queried elements. Any element with both size & layout containment can be queried using a new @container rule, with similar syntax to existing media-queries.

The approach has been approved by the CSS Working Group, to be added in CSS Containment Level 3, with me as one of the authors.

See the Contain 3 Project for issues and progress.

Establishing Containers

The first step is to establish containers. Any element can become a container, by adding layout, size (generally inline-size), and style containment:

/* Establish containers */
main, aside {
contain: layout inline-size style;
}

This syntax works in the prototype, but is clearly not ideal for readable and clear code. There is an open issue to discuss better syntax for establishing query containers

Writing Queries

Each container creates a containment context that can be queried by their descendant elements. We can query the current containment context (the nearest ancestor container) using an @container rule that is very similar to existing @media queries:

/* Change styles according to container size */
@container (min-width: 35em) {
.media {
grid-gap: 1rem;
grid-template: "media content" auto / max-content 1fr;
}
}

The .media class above is now responsive to any container it is in. Each instance of the .media class will query its nearest container.

That means we can have one .media element that moves around, responding to the context we put it in – or multiple .meia elements, each one responding individually to its own location.

Prototype

Chrome has released a prototype in their nightly build. To experiment with the feature, and leave feedback while it is still in development:

  1. Download Chrome Canary,
  2. Go to chrome://flags in the url bar, and
  3. Search for “CSS Container Queries” & enable the experimental feature
  4. Restart the browser

This is a draft prototype and may not match the final design.

Demos & Articles

For a quick introduction, check out:

Or dig into more resources, for the full details:

‘code’ orgs

2008→

OddBird

Co-Founder: Custom web applications, developer tools, and training

2016→

CSS Tricks

Staff Writer: Blog for people who make websites

2017→

Sass

Core Contributor: CSS with superpowers

2020→

W3C CSS Working Group

Invited Expert: Developing specifications for the CSS language

2020→

Google Chrome

Open Consultant: New specifications & browser priorities

2019→2020

Mozilla Developer

DevRel Contractor: Videos, articles, & tools from Mozilla (and OddBird)

122 ‘code’ episodes

Live Q&A with Miriam @ Front-end Development, South Africa

May 5

| talk | Online

I’ve spent nearly two decades learning, teaching, and writing CSS – as a founder at OddBird, a member of the Sass core team, and an Invited Expert on the CSS Working Group.


Container Queries Explainer & Proposal @ CSSWG

May 2

| article

Media-queries allow an author to make style changes based on the overall viewport dimensions – but in many cases, authors would prefer styling modular components based on their context within a layout.

Container Queries & The Future of CSS @ Web Directions, Hover

Apr 23—30

| talk | Online

New CSS proposals like Container Queries, Cascade Layers, Scoped Styles, and Nesting are all aimed at improving the way we write responsive components and design systems.

Beyond CSS Variables @ An Event Apart Spring Summit

Apr 19—21

| talk | Online

CSS Custom Properties (aka Cascading Variables) have gained broad browser support since 2015 – but what are they good for, and why do we need them?

Very Extremely Practical CSS Art @ CSS Tricks

Dec 8, 2020

| article

“What is one thing you learned about building websites this year?”

CSS, Sass, and Playwriting @ Enjoy The Vue

Nov 30, 2020

| podcast

I join Ari, Ben, and Tessa to talk about getting into CSS from other languages, the absurdly massive problem CSS is designed to solve, and the mental model behind the language.

Open CSS Notebook @ css.oddbird.net

Nov 17, 2020

| code

As I spend more of my time working on the CSS language, I wanted a place to take notes and explore new ideas in the open.

Dissecting CSS Conventions @ An Event Apart Fall Summit

Oct 26—28

| talk | Online

How do we write code that is modular & maintainable, in a language designed to be systematic & contextual?

When Variables Cascade @ SmashingConf Austin/NY

Oct 13—14

| talk | Online

The Cascade makes CSS unique – forcing us to revisit even the most common programming feature: the variable.

CSS is Rad @ Design 4 Drupal Webinar Series

Sep 9, 2020

| talk | Online

The web is designed to work across platforms, devices, languages, and interfaces – but how can we possibly design for that unknown and always-changing canvas?

CSS is Rad @ SmashingConf Live

Aug 20—21

| talk | Online

Design Engineering Handbook @ inVision

Aug 18, 2020

| interview

Learn how design engineering brings together form and function.

Dynamic CSS @ Shift Remote

Aug 6, 2020

| talk | Online

Don’t let the declarative syntax fool you – CSS is a powerful and dynamic programming language.

Custom Property “Stacks" @ CSS Tricks

Jun 22, 2020

| article

CSS Custom Properties allow us to manage and control both cascade and inheritance in new ways.

Resilient Web Systems @ Smashing Workshops

May 7—22

| workshop | Online

From building beautiful sites to maintaining complex design systems across multiple applications, CSS is the web-language of design.

Design Systems AMA @ Jina Anne

May 5, 2020

| podcast

Jina and I answer questions about CSS, Sass, Design Systems, and more!

Authoring the future of CSS @ Party Corgi

Apr 13, 2020

| podcast

A spinoff of the Party Corgi Network discord. I chat with Chris Biscardi about The CSS Working Group, open-source projects, art, and music.

Embracing the Universal Web @ CSS Tricks

Nov 26, 2019

| article

“What about building websites has you interested this year?”

Selector Support Queries @ Mozilla Developer

Nov 20, 2019

| video

Firefox 69 was the first to implement selector feature queries, but other browsers are following suit. I’ll show you how it works, and how to start using this new feature query right away.

CSS is Rad @ Front Range Front End

Nov 7, 2019

| talk | Denver, CO

Overflow-Wrap in CSS @ Mozilla Developer

Nov 6, 2019

| video

Horizontal text overflow has always been difficult to manage on the web. The default visible overflow is designed to make sure content remains accessible no matter the size of a containing box, but it’s not our only option.

CSS Most Normalizer-est

Nov 2, 2019

| code lol

Why waste your time on half-measures? Make your site THE MOST NORMALEST with this ULTIMATE CSS RESET.

Scroll Snap in CSS @ Mozilla Developer

Oct 31, 2019

| video

When we’re scrolling down a page, or through a gallery of images, snap-targets can help guide us from one section or image to the next. In the past, developers have used JavaScript to hijack scrolling, but now we can manage scroll alignment directly in CSS with only a few lines of code.

On Sass & CSS @ Shop Talk Show

Oct 28, 2019

| podcast

I drop by the show to talk about Sass in 2019, design tokens, Oddbird, unused CSS, new CSS properties, and Dave & Chris’ explanation of revert.

Inner & Outer Values of the Display Property @ Mozilla Developer

Oct 28, 2019

| video

The display property has been in CSS from the beginning, handling everything from block and inline boxes to list-items and full layout systems like flexbox or grid. Now the display syntax is getting an upgrade to match it’s multiple uses.

Why isn’t this CSS doing anything? @ Mozilla Developer

Oct 21, 2019

| video

There are a number of property & value combinations that can lead to CSS being inactive, and now Firefox will tell you why. Open the developer tools, and look for the greyed-out property with an info-box on hover.

Laying out Forms using Subgrid @ Mozilla Developer

Oct 16, 2019

| video

It’s a common pattern to align form labels and inputs in grid-like layout. I’ll show you how to do it quickly using CSS subgrid, with several quick fallbacks.

Subgrid for Better Card Layouts @ Mozilla Developer

Oct 15, 2019

| video

Card layouts are popular on the web, rows and columns of boxes with similar content. CSS grids can help align those cards, but it’s still be hard to line-up content inside the cards – headers and footers that might need more or less room.

CSS is Rad @ Smashing Conf NY

Oct 15—16

| talk | New York, NY

The web is designed to work across platforms, devices, languages, and interfaces – but how can we possibly design for that unknown and always-changing canvas?

Faster Layouts with CSS Grid @ Mozilla Developer

Oct 14, 2019

| video

For years, we’ve struggled to build resilient layouts on the web, but CSS Grid promises to change all that – and you can start using it now, with only a few properties and basic concepts.

CSS Revert @ Mozilla Developer

Oct 9, 2019

| video

I’ve often used initial and unset in my CSS – global keywords that can be applied to any property. The difference is small, but important: unset allows inheritance, while initial does not. But then Firefox implemented revert and I was confused – how is this one different from the others?!

Introducing Sass Modules @ CSS Tricks

Oct 7, 2019

| article

Sass recently launched a new module system. The new syntax will replace @import with @use and @forward – a big step forward for making Sass partials more readable, performant, and safe.

Why is CSS so Weird? @ Mozilla Developer

Oct 3, 2019

| video

Love it or hate it, CSS is weird: not quite markup, not quite programming in the imperative sense, and nothing like the design programs we use for print. How did we get here?

Styling Lists in CSS @ Mozilla Developer

Oct 1, 2019

| video

When you create lists in HTML, browsers add bullet-points or numbers we call list markers. Now CSS gives us the tools to style those list markers, and even create our own!

User Unfriendly @ Agnes Scott College

Sep 17, 2019

| talk | Atlanta, GA

A project-manager’s reflections on human-centered problem-solving, client communication, and user feedback in agile web development.

F*CSS

Aug 28, 2019

| code lol

In the CSS naming-convention arms race to lowest specificity, I’ve decided to only use universal * selectors. I call it F*CSS.

Dynamic CSS @ Develop Denver

Aug 15—16

| talk | Denver, CO

Agile Design Systems @ Agile Alliance

Aug 6, 2019

| talk | Washington, DC

Style Guides & Pattern Libraries are great tools for documenting the relationships between code and design, but beautiful docs are only half the battle.

Design Systems & CSS @ Views on Vue

Jul 2, 2019

| podcast

We start by talking about design systems and design tooling – how they differ, and the problems they solve.

CSS Custom Properties @ Smashing Magazine

Jul 1, 2019

| article

Pushing past the “variable” metaphor, CSS Custom Properties can provide new ways to balance context and isolation in our patterns and components.

User Unfriendly @ Design 4 Drupal [keynote]

Jun 26, 2019

| talk | Boston, MA

User Unfriendly @ Open Source Conference

Jun 20, 2019

| talk | Denver, CO

Dynamic CSS @ Generate New York

Apr 24—25

| talk | San Francisco, CA

Advanced CSS & Sass @ Generate New York

Apr 24, 2019

| workshop | San Francisco, CA

Has CSS finally come of age? @ Creative Bloq

Apr 23, 2019

| interview

Steve Jenkins interviews me about the state of CSS, and what’s coming next for the language – from Intrinsic Design to Dynamic CSS.

Advanced CSS & Sass @ Smashing Conf

Apr 18, 2019

| workshop | San Francisco, CA

From building beautiful sites to maintaining complex design systems across multiple applications, CSS is the web-language of design.

Dynamic CSS @ Smashing Conf

Apr 16—17

| talk | San Francisco, CA

Dynamic CSS @ VueConf US

Mar 26—27

| talk | Tampa, FL

On Dynamic CSS @ Thunder Nerds

Mar 26, 2019

| podcast

Thunder Nerds interview me before her talk at VueConf US 2019.

User Unfriendly @ Agile Denver

Mar 18, 2019

| talk | Denver, CO

Don’t Use My Grid System @ Boulder Python

Feb 12, 2019

| talk | Boulder, CO

Explore the history of web layout with the creator of Susy – why grid systems exist, how they work, and practical tips to avoid using them.

Don’t Use My Grid System @ Covalence Conf

Jan 16, 2019

| talk | San Francisco, CA

Fonts & more @ Views on Vue

Dec 4, 2018

| podcast

The panel and the guest talk about grid systems, fonts, and more!

Dynamic CSS @ Front Range Front-End

Nov 1, 2018

| talk | Denver, CO

Agile Design Systems @ Agile Denver

Oct 22, 2018

| talk | Denver, CO

Dynamic CSS @ Full Stack Fest

Sep 6, 2018

| talk | Barcelona, Spain

Ethics, ES6 in Practice, and Dynamic CSS @ TalkScript

Sep 6, 2018

| podcast

On Episode 18, the TalkScript team continues the live-ish at JSConfUS podcast series with guests Myles Borins, Tim Doherty, and Miriam Suzanne. Listen in!

Dynamic CSS @ JSConf US

Aug 21, 2018

| talk | Carlsbad, CA

Dynamic CSS @ CSSConf Argentina

Aug 18, 2018

| talk | Buenos Aires, Argentina

Planning Your Web Project @ Boost Biz Ed

Jul 11, 2018

| talk | Westminster, CO

A non-technical guide for taking your project from concept to launch, without ever losing sight of the goals.

Don’t Use My Grid System @ Beyond Tellerand

May 7, 2018

| talk | Düsseldorf, Germany

User Unfriendly @ AIGA Colorado

Apr 26, 2018

| talk | Denver, CO

User Unfriendly @ Creative Connections

Apr 16, 2018

| talk | Denver, CO

Agile Design Systems @ Front-End Front Range

Apr 5, 2018

| talk | Denver, CO

User Unfriendly @ Metro State Mobile Prototyping

Apr 5, 2018

| talk | Denver, CO

Agile Design Systems @ VueConf US

Mar 26, 2018

| talk | New Orleans, LA

Agile Design Systems @ Tech Confluence

Mar 21, 2018

| talk | Denver, CO

18 designers predict UI/UX trends for 2018 @ Figma Design

Dec 15, 2017

| interview

Planning Your Web Project @ EdTech Colorado

Dec 12, 2017

| talk | Denver, CO

Don’t Use My Grid System @ Clarity

Nov 28, 2017

| talk | San Francisco, CA

Don’t Use My Grid System @ CSS Dev Conf

Oct 9, 2017

| talk | New Orleans, LA

Code Patterns @ Refresh Denver

Sep 13, 2017

| talk | Denver, CO

Style Guides & Pattern Libraries are great tools for documenting the relationships between code and design, but beautiful docs are only half the battle.

Practical Layouts, Past & Future @ Women Who Code Fort Collins

Aug 30, 2017

| talk | Fort Collins, CO

Don’t Use My Grid System @ DjangoCon US

Aug 14, 2017

| talk | Spokane, WA

More CSS Charts, with Grid & Custom Properties @ CSS Tricks

Aug 11, 2017

| article

Inspired by Robin Rendle, I demonstrate some of my early experiments combining CSS Grids and custom properties to create dynamic layouts and data-visualizations.

Practical Layouts, Past & Future @ Develop Denver

Aug 10, 2017

| talk | Denver, CO

Practical Layouts, Past & Future @ Refresh Denver

Jun 14, 2017

| talk | Denver, CO

Fun with Viewport Units @ CSS Tricks

Jun 5, 2017

| article

Viewport units have been around for several years now, with near-perfect support in the major browsers, but I keep finding new and exciting ways to use them. I thought it would be fun to review the basics, and then round-up some of my favorite use-cases.

Code Patterns @ Front Range Front End

Jun 1, 2017

| talk | Denver, CO

Getting Started with CSS Grid @ CSS Tricks

Feb 20, 2017

| video

It feels like CSS Grid has been coming for a long time now, but it just now seems to be reaching a point where folks are talking more and more about it and that it’s becoming something we should learning.

Losing Control @ UVA Scholars’ Lab

Jan 23, 2017

| talk | Charlottesville, VA

Some Kind of Resistance Tour @ Open Grounds

Jan 23, 2017

| journal | Charlottesville, VA

It’s been a month since our country pseudo-elected a bigoted blow-hard for president. I’m heading to DC to protest his inauguration in January, visit friends, and go on a mixed-media resistance tour…

Some Kind of Resistance Tour @ Women’s March

Jan 21, 2017

| journal | Washington, DC

Some Kind of Resistance Tour @ Small Rain

Jan 19, 2017

| journal | Fredrick, MD

Some Kind of Resistance Tour @ House Show

Jan 18, 2017

| journal | Silver Spring, MD

Some Kind of Resistance Tour @ House Show

Jan 17, 2017

| journal | Baltimore, MD

Some Kind of Resistance Tour @ Wooden Shoe Books

Jan 16, 2017

| journal | Philadelphia, PA

Some Kind of Resistance Tour @ in your ear

Jan 15, 2017

| journal | Washington, DC

Some Kind of Resistance Tour @ The Operating System

Jan 13, 2017

| journal | Brooklyn, NY

Code Patterns @ Gotham Sass

Jan 12, 2017

| talk | New York, NY

Some Kind of Resistance Tour

Dec 9, 2016

| journal

It’s been a month since our country pseudo-elected a bigoted blow-hard for president. I’m heading to DC to protest his inauguration in January, visit friends, and go on a mixed-media resistance tour…

Code Patterns @ CSSDay.io

Dec 3, 2016

| talk | Chandler, AZ

Loops in CSS Preprocessors @ CSS Tricks

Dec 2, 2016

| article

No matter what acronym drives your selectors (BEM, OOCSS, SMACSS, ETC), loops can help keep your patterns more readable and maintainable, baking them directly into your code. We’ll take a look at what loops can do, and how to use them in the major CSS preprocessors.

*Beyond Pixels Profile @ Net Magazine

Dec 1, 2016

| interview

Miriam Suzanne creates experimental experiences with her band and her fellow developers.

An Interview with Miriam Suzanne @ CSS Tricks

Oct 15, 2016

| article

Chris Coyier interviews Miriam when she joins the CSS Tricks team as a Staff Writer. We talk about gettting started in the industry, name confusion, fouding OddBird, building Susy, and more.

Versioning Show, Episode 8 @ SitePoint

Oct 13, 2016

| podcast

In this episode of the Versioning Show, Tim and David are joined by Miriam Suzanne, best known for Susy, a responsive layout toolkit for Sass. They discuss going from being a lurker to finding your voice, the importance of writing about what you’re learning, stumbling into fame, approaching new projects, and unit testing in Sass.

Sass Map Magic @ CSSConf 2016

Sep 26, 2016

| talk | Boston, MA

Maps are a powerful data type in Sass – perfect for managing color and scale palettes, framework configuration, data storage, and more.

Sass Toolkits, Live Q&A @ SitePoint

Aug 18, 2016

| interview

Code Patterns @ CascadiaFest

Aug 3, 2016

| talk

Code Patterns @ CSS Summit

Jul 26, 2016

| talk

Code Patterns @ DublinCSS

May 19, 2016

| talk

Code Patterns @ Clarity

Mar 31, 2016

| talk | San Francisco, CA

Jump Start Sass @ SitePoint

Mar 22, 2016

| book

Using Sass, you can write your stylesheets in a more concise, dynamic, and readable way, and cut down many of the repetitive tasks that come with writing vanilla CSS. This book provides a thorough introduction to Sass for the beginner. Co-writen with my friend Kitty Giraudel.

Herman @ OddBird

Nov 18, 2015

| project

Design systems streamline development, communication, and consistency – but often rely on dedicated teams and extended budgets.

User Unfriendly @ SassConf 2015

Nov 11, 2015

| talk | Austin, TX

Sassy Toolkits @ Frontend Zurich

Aug 28, 2015

| talk | Zurich, Switzerland

a case-study in building and sharing open-source Sass

Sass Map Magic @ CSS Summit

Jul 7, 2015

| talk | Online

Sassy Toolkits @ WordCamp Denver

Jun 13, 2015

| talk | Denver, CO

Sass Map Magic @ Future Insights Live

Jun 2, 2015

| talk | Las Vegas, NV

Accoutrement @ OddBird

Oct 30, 2014

| project

Design systems must be meaningful to both humans and machines Accoutrement provides Sass design-token management that improves readability and consistency, while encouraging automation.

Sass Map Magic @ SassConf 2014

Oct 2, 2014

| talk | New York, NY

Sass Map Magic @ BlendConf

Sep 12, 2014

| talk | Charlotte, NC

Your Own Damn [Susy] System @ Bmore Sass

Apr 24, 2014

| talk | Baltimore, MD

an introduction to the Susy layout toolkit

Show Your Work & Share Your Toys @ Camp Sass

Apr 19, 2014

| talk | San Francisco, CA

Your Own Damn [Susy] System @ The Mixin

Apr 16, 2014

| talk | San Francisco, CA

Organizing Sass Partials @ NYCSass Meetup

Nov 19, 2013

| talk

Show Your Work & Share Your Toys @ SassConf 2013

Oct 12, 2013

| talk | New York, NY

True @ OddBird

Jun 6, 2013

| project

True is a full-featured unit-testing library for Sass. The core functionality is written in pure SassScript, so it can be used anywhere Sass is compiled. Advanced features are available with our JS test-runner integration.

Susy 1.0 Release

Aug 14, 2012

| code

Sass Striped Backgrounds

Jul 20, 2012

| code

Into the Green Green Mud @ greengreenmud.com

Feb 21, 2012

| novel

A novel about new love, moving apart, and what comes next. A love story, and an after-love story – told wiith poetry and pictures.

Susy @ OddBird

Jul 13, 2009

| project

Susy is a lightweight grid-layout engine for Sass, designed to simplify and clarify responsive grid layouts without ever getting in your way. Originally released in 2009, Susy has become one of the most popular layout frameworks on the web.

Copyright © 2021

Miriam's face

Miriam Eric Suzanne

I’m an artist, activist, teacher, and web developer. As a co-founder of OddBird, Teacup Gorilla, and Grapefruit Lab I hope to create art & software that celebrate the queer complexity of human experience.

Name: Email:

Message:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK