CSS3 Features You May Not Be Aware Of: Flexbox, Grid Layouts, Custom Properties, Transitions, Animations, and Multiple Backgrounds
Cascading Style Sheets (CSS) continue to evolve and the latest versions may have some features that you may not even be aware of. Here are some of the major improvements and methodologies introduced with CSS3, along with code examples:
- Flexible Box Layout (Flexbox): a layout mode that allows you to create flexible and responsive layouts for web pages. With flexbox, you can easily align and distribute elements within a container. n this example, the .container class uses display: flex to enable flexbox layout mode. The justify-content property is set to center to horizontally center the child element within the container. The align-items property is set to center to vertically center the child element. The .item class sets the background color and padding for the child element.
<div class=”container”>
<div class=”item”>Centered Element</div>
</div> .container {
display: flex;
justify-content: center;
align-items: center;
height: 200px;
}
.item {
background-color: #ddd;
padding: 20px;
} <div class=”grid-container”>
<div class=”grid-item”>Item 1</div>
<div class=”grid-item”>Item 2</div>
<div class=”grid-item”>Item 3</div>
<div class=”grid-item”>Item 4</div>
</div> .grid-container {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 20px;
}
.grid-item {
background-color: #ddd;
padding: 20px;
}