Created
February 12, 2019 21:50
-
-
Save tomhodgins/71acf423dd4a043138ef28037dbb02f1 to your computer and use it in GitHub Desktop.
You can read more about working with caffeinated style sheets here: https://github.com/tomhodgins/caffeinated-style-sheets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset=utf-8> | |
<meta name=viewport content="width=device-width, initial-scale=1"> | |
<title>Converting Media Queries into Element Queries in 2019</title> | |
<div>Element query test</div> | |
<style> | |
body { | |
margin: 0; | |
} | |
div { | |
padding: 1em; | |
} | |
/* Convert a media query like this */ | |
@media (min-width: 500px) { | |
div { | |
color: hotpink; | |
} | |
} | |
/* Into an element query like this */ | |
@supports (--element("div", {"minWidth": 500})) { | |
[--self] { | |
background: lime; | |
} | |
} | |
</style> | |
<script type=module> | |
import deqaf from 'https://unpkg.com/deqaf' | |
import element from 'https://unpkg.com/jsincss-element-query/index.vanilla.js' | |
deqaf({stylesheet:{element}}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Upon the first load it will download the JavaScript plugins:
Together these look like they're taking between 2-3kb, but on subsequent page loads the browser is able to cache these, resulting in 0b transfer:
Not only is this less code, but it runs about 10x faster than EQCSS as well (though it doesn't support all of the same features), so if you were wanting to do something similar to this I'd check out these newer plugins!