Here's the JSFiddle, and here's the Create a div and give it a class of out-box. box-s 154 1 10. } Adding a custom aspect ratio. Go to the Lens tool tab or long-press the Crop tool in the Cursor toolbar. Select Add aspect ratio from the list. Add a name and the ratio dimensions needed in the dialog box. Press OK. The new ratio will appear in the Ratio drop-down menu. background-size: cover; Scale the image, while preserving its intrinsic aspect ratio (if any), to the smallest size such that both its width and its height can completely cover the background positioning area. As @web-tiki 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. .container I find two ways, but I don't want to do this: remove img-box wrap. Follow. The CSS property aspect-ratio lets you create boxes that maintain proportional dimensions where the height and width of a box are calculated automatically as a ratio. It works at the first level, but when trying to do the same thing inside of the div maintaining aspect ratio, the padding-bottom percentage seems to get applied to the width So for the 16:9 aspect ratio, it means that the ratio is 16 units of width to 9 units of height. There are several ways to specify a fixed aspect ratio on an element like a div, here are 2 of them: 1. The aspect-ratio CSS property div { Using aspect-ratio css property. Cover always fills the browser window, cutting off some hair or ears in the process, which is what I personally prefer for most cases. img { The aspect ratio of an element describes the proportional relationship between its width and height. Select ImageBrowse and select the image you want to crop or resize.Drag-and-drop the image file.Paste the image from the clipboard (Ctrl-V or V). In order to maintain the aspect ratio of a div with CSS create flexible elements that keep their aspect ratio (4:3, 16:9, etc.) The aspect-ratio property is good for controlling aspect ratio of div elements if the div elements are supposed to vary in size. .person { width: 180px; aspect-ratio: 1; } If the two values for aspect ratio are the same, we can write aspect-ratio: 1 instead of aspect-ratio: 1/1. Press the Menu key on your VIZIO remote.Use the arrow keys on the remote to highlight System, and press the OK key.Use the arrow keys on the remote to highlight Aspect Ratio and then the OK key.You'll now see different option to choose from. For the auto value, height will be adjusted automatically according to the size of the image like this: Now, we will change the aspect ratio like this: .images{ aspect-ratio: 2 / 1; width: 400px; } Its a ratio of width to height. Just create a wrapper
with a percentage value for padding-bottom , like this: .demoWrapper { Step 2) Add CSS: Add a percentage value for padding-top to maintain the aspect ratio of the DIV. When browsers render an , they maintain the aspect ratio for the image. use max-height: 100vh; max-width: 100vw; in img tag. Aspect ratio is an image projection attribute, which determines the proportional relationship between the width of an image and its height. Yesterday this Medium post by Noam Rosenthal was brought to my attention when CSS Tricks called it a clever aspect-ratio trick that involves using an inline SVG with a viewBox to push out the size, and CSS Grid to overlay the content. I stumbled upon what I consider a smart solution for this problem, using