The NEW CSS aspect ratio property

preview_player
Показать описание
CSS has a fairly new property called aspect-ratio which has started to be available in the browsers. Albeit behind a support flag in Firefox.
This new property opens up new layout possibilities as well as helping to maintain image aspect ratios.

Рекомендации по теме
Комментарии
Автор

thanks for your explanation, sort out the doubt ^^, love your contents

umarmuzammil
Автор

Another excellent video. Thanks Steve. See you soon!

CodingNuggets
Автор

Nice tutorial.
If needed we can use variables instead of attributes and it's work :
<p style="--ratio-w: 1; --ratio-h: 3">

aspect-ratio: var(--ratio-w) / var(--ratio-h);

papadong
Автор

geezlus, another one... trying to fix something and you're the first meaningful result

vizunaldth
Автор

Very good!!....thank
I made a custom video component ( webComponent ) and i spent days to find a solution to keep the video aspect ratio when resizing the window.
I wanted my vidéo screen to always be 16/9 and any kind of video format could fit in it ( 1.33 1.66 1.77 1.85 2.35 horizontal vertical orientation etc....)
It works now but my code is to complicated.
Do you have a good solution to solve this 16/9 video screen containing any video format?
Thanks again for this tip and as always thanks for teaching!!

jeanmarcpourchel
Автор

Ever thought about making a video about node.js websocket handshake?

gledianlalushllari
Автор

Hey Steve, could you make videos for making the site responsive and media-queries, im having hard time while making sites responsive

suatbayrak
Автор

I don't understand why someone would ever want to do this. You said it's used to hold the space for the image or other elements, but why would I bother if the space will be given to the image and the other elements anyways after the site finishes reloading?

enriquesneffels
Автор

What if you want to perserve space on the screen for an image which you don't know the height and width of? How would you do this in a big website with lots of images all different sizes?

mractorbanner
Автор

When I set width and height in the image, the aspect ratio is set for me automatically, i dont need to add aspect-ratio: .., is it supposed to be like that ?

radoslavtsanev