Container Queries: Style Queries

My colleague Una gives a great overview of Style Queries and its use cases. Style queries let you query the style of any parent element within a page and apply styles to its children based on the styles of its parent. The cool part is that this matching is done against on the computed value …


This content originally appeared on Bram.us and was authored by Bramus!

My colleague Una gives a great overview of Style Queries and its use cases.

Style queries let you query the style of any parent element within a page and apply styles to its children based on the styles of its parent.

The cool part is that this matching is done against on the computed value of a parent.

@container style(font-style: italic) {
  span,
  i,
  .etc {
    background: lavender;
  }
}

My favorite use case is grouping styles with higher-order variables, where you can set a bunch of CSS property values based on a Custom Property Value – Yep, just like the Higher Level Custom Properties proposal I covered a long time ago.

@container style(--theme: dark) {
  .card {
    background: royalblue;
    border-color: navy;
    color: white;
  }

  .card button {
    border-color: navy;
    background-color: dodgerblue;
    color: white;
  }
}

And oh, here’s the best part of it all: Style Queries based on Custom Properties are already available in Chrome behind the Experimental Web Platform Features feature flag!

See the Pen
Style query test — card themes
by Una Kravets (@una)
on CodePen.

Container Queries: Style Queries →


This content originally appeared on Bram.us and was authored by Bramus!


Print Share Comment Cite Upload Translate Updates
APA

Bramus! | Sciencx (2022-10-13T22:29:15+00:00) Container Queries: Style Queries. Retrieved from https://www.scien.cx/2022/10/13/container-queries-style-queries/

MLA
" » Container Queries: Style Queries." Bramus! | Sciencx - Thursday October 13, 2022, https://www.scien.cx/2022/10/13/container-queries-style-queries/
HARVARD
Bramus! | Sciencx Thursday October 13, 2022 » Container Queries: Style Queries., viewed ,<https://www.scien.cx/2022/10/13/container-queries-style-queries/>
VANCOUVER
Bramus! | Sciencx - » Container Queries: Style Queries. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/10/13/container-queries-style-queries/
CHICAGO
" » Container Queries: Style Queries." Bramus! | Sciencx - Accessed . https://www.scien.cx/2022/10/13/container-queries-style-queries/
IEEE
" » Container Queries: Style Queries." Bramus! | Sciencx [Online]. Available: https://www.scien.cx/2022/10/13/container-queries-style-queries/. [Accessed: ]
rf:citation
» Container Queries: Style Queries | Bramus! | Sciencx | https://www.scien.cx/2022/10/13/container-queries-style-queries/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.