Using the currentColor property to change SVG color
July 31, 2024Custom CSS Text Selection Color
August 27, 20241. The min()
Function
The min()
function allows you to set a CSS property to the lowest value from a list of values. This is useful when you don’t want a property to go above a certain value.
Example:
.element {
width: min(50vw, 500px);
}
In this example the width of the element will be 50% of the viewport width (50vw
), but not more than 500px. This is useful to prevent elements from becoming too wide on large screens.
Use Cases:
- Limiting the width of images or containers to not go too big on wide screens.
- Setting responsive typography that doesn’t become too big.
2. The max()
Function
The max()
function sets a CSS property to the highest value from a list of values. This is useful when you want a property to have a minimum value.
.element {
height: max(100px, 10vh);
}
Here the height of the element will be at least 100px or 10% of the viewport height (10vh
), whichever is larger. This ensures the element is tall enough on large screens.
Use Cases:
- Buttons or interactive elements to have a minimum size for usability.
- Containers or sections to be visible on smaller screens.
3. The clamp()
Function
The clamp()
function is a swiss army knife, it combines the functionality of min() and max(). It takes three arguments: a minimum value, a preferred value and a maximum value. The clamp() function will keep the property within the defined range.
.element {
font-size: clamp(1rem, 2.5vw, 2rem);
}
Here the font size of the element will be at least 1rem, at most 2rem and will scale proportionally between these values based on the viewport width (2.5vw
). This allows for smooth responsive typography without going above the defined limits.
Use Cases:
- Flexible design for different device sizes.
- Responsive text GenerationStrategy