min(val1, val2) | the smaller value of the two |
max(val1, val2) | the greater value of the two relative values, e.g., fractions |
minmax(min, max) | a fit value between min and max |
clamp(min, val, max) | the middle value is in effect, until hit by limits |
Not only for width, but, e.g., for font-sizes
Flex makes the trick by wrapping, growing and shrinking where needed
.cluster{
display: flex;
flex-wrap: wrap;
gap: 1rem;
transition: width 3s;
width: 100%;
}
.cluster:hover {
width: 10%;
}
.cluster-item{
background-color: rgba(0,0,255,0.3);
border: 1px solid blue;
flex-grow: 1;
}
Hover to examine, the last column shows the respective settings:
grid-template-columns: 1fr 1fr 1fr 1fr 3fr;
grid-template-columns: 250px 100px 100px 3fr 1fr;
grid-template-columns: 1fr 1f 1fr 250px;
repeat(3, 1fr)
The first parameter is multiplier, in this context, the number of columns
The second parameter tells the size of each column
grid-template-columns: repeat(3, 1fr) 250px;
grid-template-columns: repeat(3, minmax(100px, 1fr)) 250px;
The last part (250px) adds to the "flexibility buffer". It takes what is left from 3 * minmax(), if space < the calculated width.
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)) 250px;
vs.
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)) 250px;
auto-fill: the min of 100px is used,
auto-fit: the max of 1fr is used instead.
width | min-width | max-width | height | min-height | max-height| aspect-ratio | color | resolution | orientation | scan ...
@media (min-width: 768px) { css-rule }
@media (min-width: 768px) and (max-width: 991px) { css-rule }
all | aural | braille | handheld | print | projection | screen | tty | tv | embossed | speech ...
@media (print) { css-rule }
@media (min-width: 700px), handheld and (orientation: landscape){ css-rule }
For more, check this site W3Schools material
p {
color: blue;
}
/* Remember, non-overlapping widths!*/
@media (min-width: 1200px) {
rules for wide screens only
}
@media (min-width: 992px) and (max-width: 1199px) {
rules for laptop sized screens
}
Small phone | < 600px |
Phone | 600px - 767px |
Tablet | 768px - 991px |
Desktop | 992px - 1199px |
Wide desktop | >= 1200px |
/* Extra small devices (phones, 600px and down) */ @media only screen and (max-width: 600px) {...} /* Small devices (portrait tablets and large phones, 600px and up) */ @media only screen and (min-width: 600px) {...} /* Medium devices (landscape tablets, 768px and up) */ @media only screen and (min-width: 768px) {...} /* Large devices (laptops/desktops, 992px and up) */ @media only screen and (min-width: 992px) {...} /* Extra large devices (large laptops and desktops, 1200px and up) */ @media only screen and (min-width: 1200px) {...}
These five Typical Device Breakpoints are represented by W3Schools as a well-accepted de facto standard.
Inspiration got from the css-tricks demo. Media queries have three different ranges:
<!doctype html>
<html lang="en">
<head>
Bootstrap demo
</head>
<body>
Hello, world!
</body>
</html>
d-sm-none makes the middle column to disappear in small displays (resize the window to see the effect)
Jumbo
1 of 3
Variable width content
3 of 3
1 of 3
Variable width content
3 of 3