How to inspect CSS container queries | DevTools Tips

 

[MUSIC PLAYING] JOCELYN YEEN: The CSS
container queries give us a much more dynamic approach
to responsive design. You can use dev tools to
inspect and edit them. But first of all, what exactly
are CSS container queries and why do we need them? Hmm, It would be nice
if you have a CSS expert to shed some light on this.

 

UNA KRAVETS: Hi. JOCELYN YEEN: Hey Una. UNA KRAVETS: Hey Jecelyn. Thanks for having
me on your show. I’m Una from “Designing
in the Browser.” Container queries
are a capability that completely shifts how we
think about responsive design today. For the first time, we can
look inside our page interfaces to style the
elements within them based on their parent elements. You can think of a container
query like a media query without media, but
instead of relying only on the viewport and global meta
information to adjust styles, you can use any parent
container of the element you’re targeting to adjust its styles.

 

That means that a card
like this coffee card can be placed into any
part of the interface and readjust itself to
the most optimal layout. That card now owns and dictates
its responsive logic. This is called intrinsic
design and works a lot more naturally for component-based UI architectures. You can use container
queries as an entry point to style anything from
backgrounds to borders, but in this example, we’re
mostly shifting the layout and content visibility. If this card was in a more
narrow area, like a sidebar, it could get a vertical layout. If it’s in this wider area,
it gets a horizontal layout. And if it’s in a
thumbnail, it might get a completely different layout. Container queries are
enabled by CSS containment. So the first step in getting
container queries to work is setting containment
on the parent elements.

 

 

And since we’re only looking
at the inline direction for the width of this parent
container, all we need to set is the container type inline
size on the parent. But Jecelyn, what is that
thing next to the element and the elements panel? JOCELYN YEEN: That is
the content of the batch, similar to the grid
and flexbox batch. It could help you identify the
container element on the page more quickly. Not only that, click the
batch to toggle an overlay on the container and all
its querying descendants. Over to you, Una. UNA KRAVETS: All right, let’s
take a look at the container queries declaration. Starting on mobile first,
we hide the description of the card for a narrow area. When the card size
exceeds 400 pixels, it gets a vertical layout
with the description.

 

Finally, when the card
is in an even wider area, it gets a horizontal layout
with the title on top and the image on the left. You can view and edit the
container query in DevTools. When we increase the inline
size from 400-500 pixels, the UI reflects the
results immediately. The parent element of
the query is shown above. Hover over it to view the
current container size and highlight it on the screen. Finally, to view the parent
element, click on the link and it will bring you to the
parent element right away. JOCELYN YEEN: Thanks,
Una, How can we learn more about container queries? UNA KRAVETS: Well,
for a start, you can check out some of the
container query episodes from “Designing the Browser.” JOCELYN YEEN: To learn
more about debugging container queries with DevTools go to
goo. glue/dev tools container queries. That’s all. See you for the
next DevTools tip. Bye. UNA KRAVETS: Bye. [MUSIC PLAYING].

As found on YouTube

Traffic Xtractor ᶜˡⁱᶜᵏ ᵗʰᵉ ˢⁿᵒʷᵐᵃⁿ ☃ Page 1 Of Google & YouTube In MINUTES! Software Gets As Much FREE Traffic As You Want With A FEW CLICKS OF YOUR MOUSE… NEW Features Include: Video Title & Description Curating & Optimization Google suggest keywords ⇝ Google related keywords ⇝ Bing suggest keyword ⇝ Bing related keywords

Leave a Reply

Your email address will not be published. Required fields are marked *