Technology News

Quickly Testing CSS Fallbacks

Dumb trick alert!

Not all browsers support all features. Say you want to write a fallback for browsers that doesn’t support CSS Grid. Not very common these days, but it’s just to illustrate a point.

You could write the supporting CSS in an @supports blocks:

@supports (display: grid) { .blocks { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100px, 100%), 1fr)); gap: 1rem; }
}

Then to test the fallback, you quickly change @supports (display: grid) to something nonsense, like adding an “x” so it’s @supports (display: gridx). That’s a quick toggle:

The example above doesn’t have very good fallbacks does it?! Maybe I’d attempt to write something similar in flexbox, as hey, maybe there is some small group of browsers still out there that support flexbox and not grid. More likely, I’d just write a fallback that makes things look pretty OK as a column.

If I’m fairly confident the browser supports @supports queries (oh, the irony), I could write it like:

@supports (display: grid) { /* grid stuff */
} @supports not (display: grid) { /* at least space them out a bit */ .block { margin: 10px }
}

That’s an assumption that will get safer and safer to make, and honestly, we’re probably already there (if you’ve dropped IE support).

This makes me want that @when syntax even more though, because then we could write:

@when supports(display: grid) { } @else { }

…which feels so fresh and so clean.

The 4 Best Linux Distros for Helping You Stay Anonymous
Hellraiser: The 5 Best & 5 Worst Cenobites In The Whole Franchise

Related Articles

Deciding Your Web Design Priorities

Deciding Your Web Design Priorities
A well-designed website is an incredibly important aspect of any business. Think of your website as your home base. It’s where most of your customers go to get information about…

WordPress 6.8.1 Maintenance Release

WordPress 6.8.1 Maintenance Release
WordPress 6.8.1 is now available! This minor release includes fixes for 15 bugs throughout Core and the Block Editor addressing issues affecting multiple areas of WordPress including the block editor,…

5 Free Web Design Tools You Can Use

5-free-web-design-tools-you-can-use
Whether it’s for a business or personal portfolio, a great looking website helps attract users and encourages them to engage with it. True enough, a study by Adobe shows that 38%…

The Beginner’s Guide to Learning Sass

the-beginners-guide-to-learning-sass
Writing a lot of CSS can be overwhelming that is why it is beneficial to learn Sass and LESS. They can make any web developer and designer’s life much easier. For…

Is 2024 The END Of The M1 MacBook Air?

Is 2024 The END Of The M1 MacBook Air?
Get the iVANKY FusionDock Max 1 here: https://ivanky.com/products/ivanky-docking-station-fusiondock-max-1?ref=Vfk6sd-EtlvXZKOr, use discount code: FORCREATED (valid until April 30th) It’s been nearly 4 years since the M1 MacBook Air was released. In that…