Grid enhancement
.cards { display: block; }
@supports (display: grid) {
.cards { display: grid; grid-template-columns: repeat(3, 1fr); }
}
@supports is a CSS feature query. Rules inside its block apply only when the browser accepts the tested property and value. Write a usable fallback first, then enhance it inside the query.
A successful parse test means the syntax is recognized; still test the resulting layout.
@supports (property: value) {
/* supported styles */
}.cards { display: block; }
@supports (display: grid) {
.cards { display: grid; grid-template-columns: repeat(3, 1fr); }
}@supports (display: grid) and (gap: 1rem) {
.cards { display: grid; gap: 1rem; }
}@supports selector(:has(*)) {
.card:has(img) { padding-top: 0; }
}@supports is a browser CSS feature.
Supported by all current major browsers.
Bottom line: Safe for progressive enhancement. Browsers that do not understand the at-rule ignore its block, so keep the fallback outside.
Organize cascade priority explicitly.
CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful