Unlocking the Power of CSS: Exploring Advanced Features for Modern Web Design
CSS is a powerful styling language for web development, and it constantly evolves with new features that enhance design capabilities. In my recent exploration, I came across some exciting CSS features that are worth highlighting:
clamp(): The clamp() function allows you to set a value within a specific range. It takes three parameters: the minimum value, preferred value, and maximum value. It's useful for creating responsive designs.
h1{
font-size: clamp(16px, 4vw, 24px);
}
Smooth Scroll: The scroll-behavior property enables smooth scrolling behavior when navigating through page anchors or using JavaScript scroll functions.
html{
scroll-behavior: smooth;
}
Scroll Snap: The scroll-snap CSS properties control the scroll-snap behavior, allowing content to smoothly snap to predefined positions during scrolling.
.container{
scroll-snap-type: y mandatory;
}
.container .card{
scroll-snap-align: center;
}
inset: The inset property specifies the position of an element, both horizontally and vertically, relative to its containing element.
.container{
position: absolute;
inset: 12px;
}
inline/block: The inline and block properties set the padding of an element in the inline and block directions, respectively. They are part of the CSS Logical Properties module.
.container{
/*-inline will apply for left and rightside */
padding-inline: 10px;
/*-block will apply for left and rightside */
padding-block: 20px;
}
min() / max(): The min() function allows you to set the minimum value between two or more values.
The max() function sets the maximum value between two or more values.
.container{
width: min(300px, 50%);
}
.container {
width: max(500px, 70%);
}
Line-clamp: The line-clamp property limits the number of lines of text displayed within an element, and the overflow is truncated with an ellipsis.
.text-container {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
has(): The: has() selector matches an element if it has a specific selector as its descendant, allowing for more complex CSS selectors.
div:has(p) {
background-color: yellow;
}
is(): The: is() selector is a shorthand way to write multiple selectors in a single rule, reducing redundancy.
Recommended by LinkedIn
div:is(h1, h2, h3) {
color: blue;
}
Writing mode: The writing-mode property sets the direction of block flow, which affects how content is displayed vertically or horizontally.
h1 {
writing-mode: vertical-rl;
}
Viewport Units: Viewport units (vw, vh, vmin, vmax) are relative units that allow you to size elements based on a percentage of the viewport size.
h1{
font-size: 5vw;
}