5

Day 4: the min() function

 1 year ago
source link: https://www.matuzo.at/blog/2022/100daysof-day4/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Day 4: the min() function

posted on September 29., 2022

It’s time to get me up on speed with modern CSS. There’s so much new in CSS that I know too little about. To change that I’ve started #100DaysOfMoreOrLessModernCSS. Why more or less modern CSS? Because some topics will be about cutting-edge features, while other stuff has been around for quite a while already, but I just have little to no experience with it.


The min() function takes a comma separated list of expressions. The smallest value in the list will be selected.

div {
width: min(400px, 200px, 300px);
/* width = 200px */
}

This example doesn’t make much sense because the value will always be 200px.
min() shows its true power when you use relative units.

div {
width: min(100%, 800px);
}

If the available space is below 800px, it matches 100%. If it's more than 800px, it matches 800px. This is basically a shorter version of this.

div {
width: 100%;
max-width: 800px;
}

See on CodePen.

Browser Support

ChromeFirefoxSafariSafari on iOSChrome AndroidGlobal Support
min()v79v75v11.1v11.3v7994.31%

Global support data from caniuse.com


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK