CSS Tip! ✨ You can make your component styles portable with container queries 😎 Change a card layout…
@jh3yy148 тыс. подписчиков
311 726 просмотров
10 комментариев
Комментарии из оригинального поста в X (Twitter)

@jh3yy
Here's that @CodePen link! 🚀 Each component is in a resizable container so you can see the queries in action 💪
52 отметки «Нравится»

@jh3yy
Hard to really express how magical this CSS feature is in one tweet but you can basically wave goodbye to media queries 👋 The trickiest part is conveying that to design. Instead of designing based on a whole page, the mental model needs to shift to the component level 🤔
36 отметок «Нравится»

@jh3yy
Added a video of these in action within a full layout 😍 I hadn't had the opportunity to really use container queries in the wild to fully appreciate them
24 отметки «Нравится»

@JettIsOnTheNet
@CodePen Cool. Few issues in Firefox, but can be overcome /w min- Nice element.
9 отметок «Нравится»

@jh3yy
@CodePen Yeah, you're totally right Jett, could definitely set a min-width here 😅 I put these together hastily for a talk at the end of last year and was reminded of them today 🤓
3 отметки «Нравится»

@Jeffijoe
@CodePen Didn't know about this CSS feature until now! Could you explain the difference between `container-type: size` and `container-type: inline-size`, perhaps with an example? Can't seem to trigger any discernable difference.
6 отметок «Нравится»

@jh3yy
@CodePen Sure thing Jeff! 🤙 `inline-size` deals with the inline axis which is typically width related. Whereas the `size` query gives you both height and width For example, these two demos use `size`. The beard grows with height and changes color with width 😅
18 отметок «Нравится»

@imrv0n
@CodePen Is this presently compatible with most browsers? Looks really solid.
2 отметки «Нравится»

@ICT_Consults
@CodePen Very useful, but this can also be done with media queries
1 отметка «Нравится»

@jh3yy
@CodePen Unfortunately not as cleanly 🥲 media queries deal with the size of the viewport and can't account for a components size The same card in different parts of a layout would require different classes and media queries. But shown here, not needed ✨
3 отметки «Нравится»