Loading content…
Loading content…
Master modern styling techniques using native CSS variables, native selector nesting, and container-query layouts
:root pseudo-class to make them globally accessible::root {
--primary-color: #4f46e5;
--primary-hover: #4338ca;
--text-main: #1f2937;
--spacing-md: 1rem;
--transition-fast: 150ms ease;
}
/* Using variables */
.button {
background-color: var(--primary-color);
color: #ffffff;
padding: var(--spacing-md);
transition: background var(--transition-fast);
}
.button:hover {
background-color: var(--primary-hover);
}
:root {
--bg-color: #ffffff;
--text-color: #1f2937;
}
/* Override variables on dark class */
@media (prefers-color-scheme: dark) {
:root {
--bg-color: #111827;
--text-color: #f9fafb;
}
}
body {
background-color: var(--bg-color);
color: var(--text-color);
}
.card {
background-color: #ffffff;
border: 1px solid #e5e7eb;
padding: 1.5rem;
/* Nest child elements directly */
.card-title {
font-size: 1.25rem;
font-weight: 700;
}
.card-body {
font-size: 1rem;
color: #4b5563;
}
/* Nest pseudo-classes and pseudo-elements using the '&' symbol */
&:hover {
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
.card-title {
color: #4f46e5;
}
}
}
.card-wrapper {
container-type: inline-size;
container-name: card-container;
}
.card {
display: flex;
flex-direction: column;
}
/* If the parent container is wider than 500px, change card layout to horizontal */
@container card-container (min-width: 500px) {
.card {
flex-direction: row;
gap: 1.5rem;
}
}
Senior Developer Wisdom
Common Pitfall
Modern CSS Checklist
Marking it complete updates your roadmap progress percentage.