Hi! This weekend I was experimenting with writing element queries based on the aspect ratio of an element. I learned that there is min-aspect-ratio and max-aspect-ratio support on @media queries which does the exact behaviour (and syntax) that I had desired, the only issue is that @media is limited to the browser's aspect ratio, and so these conditions can't be used to style elements based on their own aspect ratio.
And here is an extreme example, what I had in mind when I was looking for support, showing how different container queries could be written to allow a layout to recognize the aspect ratio it has and apply styles to many elements when that condition is met:
Hi! This weekend I was experimenting with writing element queries based on the aspect ratio of an element. I learned that there is
min-aspect-ratio
andmax-aspect-ratio
support on@media
queries which does the exact behaviour (and syntax) that I had desired, the only issue is that@media
is limited to the browser's aspect ratio, and so these conditions can't be used to style elements based on their own aspect ratio.I grabbed the source to EQCSS.js from http://elementqueries.com/EQCSS.js and added the following code:
Now the following syntax will work on
@element
queries with EQCSS in all browsers IE8 and up:And here is an extreme example, what I had in mind when I was looking for support, showing how different container queries could be written to allow a layout to recognize the aspect ratio it has and apply styles to many elements when that condition is met:
Code demos
I think if would be really cool if this sort of thing was in CSS!