3 ms·
Ok well, there is only one mention of clamp, min, and max. Basically clamp allows you to do what people generally do with media queries, which is actually to s
by bryanrasmussen 4y ago
Ok well, there is only one mention of clamp, min, and max.
Basically clamp allows you to do what people generally do with media queries, which is actually to set sizes of things in relation to the size of the window. Yes you can do lots of other stuff but this is what you normally do with a media query.
Let us suppose that you have a min width for 300px, a max width of 1100px and then you set the width to be something based on breakpoints.
setting a static width is silly, because it should be a percentage so that it moves between your min width and max width - so you do maybe width: 70%
you can do that with a single width: clamp (300px, 70vw, 1100px)
but of course you can also use clamp on your margins, your paddings etc.
Most of the things people use breakpoints for in day to day css are handled by clamp.
But you still have all these other things. You still have breakpoints, so if you find for example that at a certain point the percentage of your area should be greater that is to say it should be 80vw with still the same min and max you can do breakpoint width: clamp(300px, 80vw, 1100px)
As you note my usage of clamp is static value, dynamic value, static value answering to min value, preferred value, max value. I do it that way for these examples because they are the easiest to reason about, but really they could be all sorts of things. it could be clamp(dynamic based on page size, static, dynamic based on calculation of container width and height) as something one might want to do.