Comments on: Responsive Layouts, Fewer Media Queries https://css-tricks.com/responsive-layouts-fewer-media-queries/ Tips, Tricks, and Techniques on using Cascading Style Sheets. Tue, 25 Jan 2022 19:55:14 +0000 hourly 1 https://wordpress.org/?v=6.1.1 By: Temani Afif https://css-tricks.com/responsive-layouts-fewer-media-queries/#comment-1788664 Tue, 25 Jan 2022 19:55:14 +0000 https://css-tricks.com/?p=357080#comment-1788664 In reply to Paweuek.

Unfortunately, this won’t be possible with such configuration and CSS grid in general. You will need to try something else using Flexbox.
Actually I don’t see how to combine the responsiveness trick with centering.

]]>
By: Temani Afif https://css-tricks.com/responsive-layouts-fewer-media-queries/#comment-1788662 Tue, 25 Jan 2022 19:42:04 +0000 https://css-tricks.com/?p=357080#comment-1788662 In reply to AsTeRiX.

You can avoid such issue by using values like 450.05px or 450.99px. A value that the browser cannot use it (or it’s rare to be used) as width

]]>
By: Paweuek https://css-tricks.com/responsive-layouts-fewer-media-queries/#comment-1788661 Tue, 25 Jan 2022 19:41:09 +0000 https://css-tricks.com/?p=357080#comment-1788661 Hi, is there any way to center divs when they are wraped to another row?

In this codepen, they aren’t centered. https://codepen.io/t_afif/pen/bGqbgYY

]]>
By: AsTeRiX https://css-tricks.com/responsive-layouts-fewer-media-queries/#comment-1788621 Tue, 25 Jan 2022 08:11:54 +0000 https://css-tricks.com/?p=357080#comment-1788621 What about the exact 450px on Responsive card example? https://codepen.io/t_afif/pen/abyLYGy the layout is broken.

]]>
By: Curtis Wilcox https://css-tricks.com/responsive-layouts-fewer-media-queries/#comment-1788276 Mon, 17 Jan 2022 17:09:19 +0000 https://css-tricks.com/?p=357080#comment-1788276 I found when trying the Responsive Card example that if the viewport width is equal to the --w custom property value, you won’t get the desired outcome of all properties toggling between minimum and maximum clamp values. When they’re equal, --c: (100vw - var(--w)) is 0px therefore the value of both var(--c)*-1000 and var(--c)*1000 is the same, 0px, and the minimum clamp value is used for them all instead of one changing to the max value and the other changing to the minimum value.

It seems this can be avoided by using a value that can never be equal to the the viewport width. That is, use a non-whole number like --w: 450.1px;. Alternately, add a tiny percentage, like --c: (100vw - var(--w) + .1%); that might be preferable so the “breakpoint” value remains a nice, round number.

]]>
By: Max Mantel https://css-tricks.com/responsive-layouts-fewer-media-queries/#comment-1786805 Fri, 10 Dec 2021 09:08:10 +0000 https://css-tricks.com/?p=357080#comment-1786805 In reply to Kev Bonett.

I have to agree with Kev on this one. I wouldn’t use this, since media query/container query are intended for this behavior, where clamp is not.

Nevertheless I enjoyed this article. It is a cool hack to tryout and good to know that it exists but not to use in production code.

]]>
By: Temani Afif https://css-tricks.com/responsive-layouts-fewer-media-queries/#comment-1786618 Sun, 05 Dec 2021 15:02:15 +0000 https://css-tricks.com/?p=357080#comment-1786618 In reply to Ali.

I have to disagree here:
“with media query we have exact breakpoint pixel” –> I also have exact breakpoint pixel here the same way media query do. I am simulating the same behavior of media query with less of code.

“and any body can understand without reading the code.” –> you say this because you know media queries since too long and media queries are available since more than 10 years now. The fact that media queries are widely used make them “easy” but still no anyone can understand them at first glance. You have no idea the number of people that get confused between min-width/max-width or the syntax of media query or the order of media queries. let’s not talk about the specificity issues. You still need to read the DOC of media query to understand them, they are not intuitive.
My logic is “easier” than media query BUT it’s something new and anything new always seems hard because we are not used to it. We need to give it time and if people start to work with it will be “easy” because such code will be widely used and documented. Let’s not forget the fact that my logic rely on CSS variable so all you have to do is to update those variables. If they are well documented, you don’t even need to check the code. We cannot say the same for media queries

]]>
By: Ali https://css-tricks.com/responsive-layouts-fewer-media-queries/#comment-1786600 Sat, 04 Dec 2021 18:42:21 +0000 https://css-tricks.com/?p=357080#comment-1786600 Thanks for this great article I learnt a lot from it,
I think this way of responsiveness make reading css harder. with media query we have exact breakpoint pixel and any body can understand without reading the code.

]]>
By: Steven Portas https://css-tricks.com/responsive-layouts-fewer-media-queries/#comment-1786384 Mon, 29 Nov 2021 16:33:22 +0000 https://css-tricks.com/?p=357080#comment-1786384 This is wonderful!

By following along, it was simple for me to see how I could do away with Bootstraps grid layout. In a world of trying to make code smaller this eliminates the need to import that one last piece with some small additions.

.container {
    @include push--auto;
    max-width: 80%;
    display: grid;
    gap: 20px;
    grid-template-columns:
    repeat(auto-fill,
        minmax(clamp(clamp(clamp(clamp(
            100%/(var(--xl) + 1) + 0.1%, (var(--b1) - 100vw)<em>1000,
            100%/(var(--l) + 1) + 0.1%),(var(--b2) - 100vw)</em>1000,
            100%/(var(--m) + 1) + 0.1%),(var(--b3) - 100vw)<em>1000,
            100%/(var(--s) + 1) + 0.1%),(var(--b4) - 100vw)</em>1000,
            100%), 1fr));

&--5 {
    --b1: 1200px;
    --xl: 5;
    --b2: 992px;
    --l: 4;
    --b3: 768px;
    --m: 3;
    --b4: 576px;
    --s: 2;
}

&--4 {
    --b1: 1200px;
    --xl: 4;
    --b2: 992px;
    --l: 4;
    --b3: 768px;
    --m: 3;
    --b4: 576px;
    --s: 2;
}

&--3 {
    --b1: 1200px;
    --xl: 3;
    --b2: 992px;
    --l: 3;
    --b3: 768px;
    --m: 3;
    --b4: 576px;
    --s: 2;
}

&--2 {
    --b1: 1200px;
    --xl: 2;
    --b2: 992px;
    --l: 2;
    --b3: 768px;
    --m: 2;
    --b4: 576px;
    --s: 2;
}
}
]]>
By: xpy https://css-tricks.com/responsive-layouts-fewer-media-queries/#comment-1786187 Thu, 25 Nov 2021 08:08:28 +0000 https://css-tricks.com/?p=357080#comment-1786187 In reply to Kev Bonett.

I completely agree with the “expressive, readable code” but in this case you could definitely make a SASS mixin out of it and make it nice for your fellow developers.

]]>
By: tom https://css-tricks.com/responsive-layouts-fewer-media-queries/#comment-1786169 Wed, 24 Nov 2021 19:30:06 +0000 https://css-tricks.com/?p=357080#comment-1786169 Great post!
I would though split those very long complicated CSS lines into a variables with meaningful names

]]>
By: David Cardona https://css-tricks.com/responsive-layouts-fewer-media-queries/#comment-1786151 Wed, 24 Nov 2021 13:48:28 +0000 https://css-tricks.com/?p=357080#comment-1786151 Thanks for this awesome exploration! This is really high quality edge content

]]>
By: Taz https://css-tricks.com/responsive-layouts-fewer-media-queries/#comment-1786150 Wed, 24 Nov 2021 13:40:26 +0000 https://css-tricks.com/?p=357080#comment-1786150 please god bring sub grid to all browsers just to make things easier. What are they waiting for?

]]>
By: F S https://css-tricks.com/responsive-layouts-fewer-media-queries/#comment-1786148 Wed, 24 Nov 2021 10:44:59 +0000 https://css-tricks.com/?p=357080#comment-1786148 Amazing article, and I like that you explain the formulas.

I strongly prefer this to media queries, though the formulas should always be well commented or the meaning might be lost. I don’t know if I trust most programmers to even bother with that.

]]>
By: Aaron Davidson https://css-tricks.com/responsive-layouts-fewer-media-queries/#comment-1786127 Wed, 24 Nov 2021 01:14:04 +0000 https://css-tricks.com/?p=357080#comment-1786127 In reply to Aaron Davidson.

To quote Private Frazer from Dad’s Army, “We’re doomed”

Container queries will come, We’ll all say “hallelulah”, Webkit will delay implementation long enough to prop up the App Store a bit longer, squirrels will manically update npm packages and dependencies, things will break and get fixed, polyfills will multiply and everyone will rally under the new code on the block.

In the meantime there’s your solution. I just can’t think of an appropriate atomic class name to avoid repetition.

]]>