
#Css force responsive resize code#
The general concept is there.Īs already show a way to use vh/ vw, I also need a way to center in the screen, here is a snippet code for 9:16 portrait. You might have to play around with it a bit to get it to work with your own design, but this actually works surprisingly well for me. css change image on aspect ratio change css image force window to keep aspect ratio.

It tells whatever else is in video class element to take full-advantage of the real estate provided by the dynamic image by forcing its width/height to 100% of the video class element being adjusted by the image. Answers related to css keep proportion of screen when resize. It takes advantage of the way an image will maintain its proper aspect ratio when resized in an element. The way it works depends on the position properties of the video class element and the item you want have maintain a certain aspect ratio. Make sure you also remove any explicit height or width declaration within the object and embed tags that usually come with copy/pasted embed code. Firstly we’ll have a look at the two most common aspect ratio examples. In order to keep the aspect ratio of the div and prevent its content from stretching it, you need to add an absolutely positioned child and stretch it to the edges of the wrapper with: div.stretchy-wrapper If you want to maintain the aspect ratio of your div, you must add a percentage value for the padding-top property, like this: Different aspect ratios have different percentage values. Padding-bottom values for other aspect ratios and 100% width : aspect ratio | padding-bottom value

The percentage is calculated with respect to the width of the generated box's containing block (source: w3.org, emphasis mine) This relies on the fact that for padding : Let’s see an example to visualize what we have said for responsive images. If the width is fixed, the height will be fixed too. It will result in a with height equal to 75% of the width of its container (a 4:3 aspect ratio). If the width of an image is reduced to adapt to the responsive, the height will be reduced too.
