Answer the question
In order to leave comments, you need to log in
CSS: width based on height?
Good afternoon! I'm trying to use css to make the aspect ratio (16:9, 4:3, etc.) in height.
Couldn't find a solution as nothing from my experience comes to mind other than javascript (which I don't want to use for this case).
Of course, there is a great solution , but this works from the width and not the height, and I want to build a ratio from the height.
Is it possible to implement this in css?
Answer the question
In order to leave comments, you need to log in
Can you elaborate on the requirements, for what and how it will be used?
So far, an idea came to my mind only with a spacer in the form of a picture with the necessary proportions, the minimum size and the maximum compressed quality, for example, white jpg / png sizes of 16x9px and 4x3px which are 100% in height and with automatic width and made invisible, and we set the height to the blocks themselves and make them inline blocks. By setting a fixed height to the block, the image inside is stretched to the entire height of the block and its width increases proportionally, stretching the block itself in width to the proportions of the image. Plus, inside you can create an additional block for placing content by stretching and positioning it on top of everything.
Example
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question