CSS has two different box sizing models that affect how element dimensions are calculated:
Compare both models below to see how they behave differently when adjusting padding and border!
.content-box {
box-sizing: content-box;
width: 200px;
padding: 20px;
border: 2px solid var(--bs-primary);
}
.border-box {
box-sizing: border-box;
width: 200px;
padding: 20px;
border: 2px solid var(--bs-primary);
}
The CSS Box Model is fundamental to web layout. Every HTML element is treated as a box with:
Use the controls below to see how these properties affect the layout!
.example-element {
margin: 20px;
padding: 20px;
border: 5px solid var(--bs-primary);
}
Links are crucial for navigation and interaction. CSS allows us to style links in various states:
Below are different techniques for styling links. Notice how they enhance user experience and provide visual feedback!
/* Default Link */
.default-link {
color: var(--bs-primary);
text-decoration: none;
}
.default-link:hover {
text-decoration: underline;
}
/* Animated Underline */
.animated-underline {
position: relative;
text-decoration: none;
}
.animated-underline::after {
content: '';
position: absolute;
width: 0;
height: 2px;
bottom: 0;
left: 0;
background-color: currentColor;
transition: width 0.3s;
}
.animated-underline:hover::after {
width: 100%;
}
/* Color Transition */
.color-transition {
text-decoration: none;
transition: color 0.3s ease;
}
.color-transition:hover {
color: var(--bs-info);
}
/* Icon Link */
.icon-link {
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 0.5rem;
transition: transform 0.3s ease;
}
.icon-link:hover {
transform: translateX(5px);
}
Flexbox is a one-dimensional layout method for arranging items in rows or columns. It's perfect for:
Experiment with the controls below to see how these properties work together!
.flexbox-container {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: stretch;
}
CSS Grid is a two-dimensional layout system that lets you create complex layouts with rows and columns. It's ideal for:
Try different column layouts and gap sizes to understand how Grid works!
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
CSS offers two main ways to create animations:
Experiment with the examples below to see how CSS animations work!
.animated-element {
animation: rotate 1s linear infinite;
}
Experiment with different CSS properties and see their effects in real-time. Complete the micro-challenges to master each property!
/* CSS code will appear here */
Image sprites are a technique where multiple images are combined into a single image file. This approach:
Below is the actual sprite sheet image containing all states of our icons:
This single SVG file contains all icon states (normal and hover):
Each icon is 64x64 pixels. Normal states are in the top row, hover states in the bottom row.
.sprite {
width: 64px;
height: 64px;
background-image: url('images/sprite-sheet.svg');
background-repeat: no-repeat;
transition: background-position 0.3s ease;
}
.home-icon {
background-position: 0 0;
}
.home-icon:hover {
background-position: 0 -64px;
}
.email-icon {
background-position: -64px 0;
}
.email-icon:hover {
background-position: -64px -64px;
}
.settings-icon {
background-position: -128px 0;
}
.settings-icon:hover {
background-position: -128px -64px;
}
Download these starter templates and complete the exercises to practice what you've learned!
Practice working with content-box and border-box sizing models. Compare how different box sizing affects element dimensions.
Download ExerciseCreate a responsive layout using flexbox. Practice with flex container properties and alignment.
Download ExerciseBuild a responsive grid layout that adapts to different screen sizes. Practice with grid template columns and gaps.
Download ExerciseDownload these cheat sheets for quick reference to CSS concepts and properties!
Quick reference for CSS box model properties and box sizing behavior. Includes visual examples and common use cases.
Download Cheat SheetComplete guide to Flexbox properties with visual examples. Includes both container and item properties.
Download Cheat Sheet