The min-width
, and max-width
properties (and their friends for height) limit min and max to exact values, but with width of 100% will adjust to fit an area in-between them. Here, the width will be at most 200px, 100-200px if space is > 100px and < 200px, and at least 100px.
.item-static {
width: 100%;
max-width: 200px;
min-width: 100px;
}
Using clamp, instead the width will adjust between min and max based on available space, and with a preferred value of 100%
will adjust to the space if it's less than min or greater than max; this is because % values can be treated as auto
.
.item-clamp {
width: clamp(100px, 100%, 200px);
}
.item-static {
width: 100%;
min-width: 100px;
max-width: 200px;
}
.item-clamp {
width: clamp(100px, 100%, 200px);
}
.thin {
width: 75px;
}
.skinny {
width: 150px;
}
.wide {
width: 250px;
}
.red {
background-color: red;
}
.blue {
background-color: blue;
}
.green {
background-color: green;
}
<div class="thin item-static red">100px</div>
<div class="skinny item-static blue">150px</div>
<div class="wide item-static green">200px</div>
<hr>
<div class="thin item-clamp red">75px</div>
<div class="skinny item-clamp blue">150px</div>
<div class="wide item-clamp green">250px</div>
display: block
on.container
(need alsoheight:100%
on items or you won't see them) the items will both correctly overflow, the containing is an effect from flexbox,clamp
is setting correctly the min value requested if you look via devtools. So I guess the point is not reallyclamp
per se but where/how it is applied right? – Oleta