Пропустить навигацию
CSS Tip! ✨ You can make your component styles portable with container queries 😎 Change a card layout…
0:00 / 0:28

CSS Tip! ✨ You can make your component styles portable with container queries 😎 Change a card layout…

jhey ʕ•ᴥ•ʔ

@jh3yy148 тыс. подписчиков

Открыть в X
2 259 отметок «Нравится»СкачатьОригинальный пост

311 726 просмотров

CSS Tip! ✨ You can make your component styles portable with container queries 😎 Change a card layout based on size 🔥 Remove button text when it's small 🤏 .card {container-type: inline-size;} @ container (min-width: 50ch) {.info { grid-column: 2; }} CodePen.IO link below 👇

10 комментариев

Комментарии из оригинального поста в X (Twitter)

  • Фото профиля jhey ▲🐻🎈

    @jh3yy

    Here's that @CodePen link! 🚀 Each component is in a resizable container so you can see the queries in action 💪

    52 отметки «Нравится»

  • Фото профиля jhey ▲🐻🎈

    @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 отметок «Нравится»

  • Фото профиля jhey ▲🐻🎈

    @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 отметки «Нравится»

  • Фото профиля Jett Sjöberg

    @JettIsOnTheNet

    @CodePen Cool. Few issues in Firefox, but can be overcome /w min- Nice element.

    9 отметок «Нравится»

  • Фото профиля jhey ▲🐻🎈

    @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

    @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 отметок «Нравится»

  • Фото профиля jhey ▲🐻🎈

    @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 отметок «Нравится»

  • Фото профиля VoN

    @imrv0n

    @CodePen Is this presently compatible with most browsers? Looks really solid.

    2 отметки «Нравится»

  • Фото профиля ICT Consults LLC, RC1232885

    @ICT_Consults

    @CodePen Very useful, but this can also be done with media queries

    1 отметка «Нравится»

  • Фото профиля jhey ▲🐻🎈

    @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 отметки «Нравится»