Update
, , , , . , :
, 16: 9, , 270 , :
16
270/16 = 16.875
9
16.875 * 9 = 151.875
Round up to 152px
, object-fit:cover
152px is the height of an image that 270px wide and has an aspect ratio of 16:9.
Fiddle
OP, .
object-fit - CSS. . . Btw, , , - object-fit: cover, .
.bg1 {
width: 270px;
height: 152px;
object-fit: cover;
outline: 2px dashed blue;
}
.bg2 {
width: 270px;
height: 152px;
object-fit: contain;
outline: 2px dashed blue;
}
.bg3 {
width: 270px;
height: 152px;
outline: 2px dashed blue;
}
aside {
height: 100%;
width: 40%;
display: inline-block;
position: absolute;
right: 0;
top: 0;
}
figure {
height: 180px;
width: 270px;
max-width: 50%;
}
.pointer {
position: absolute;
}
.pointer b {
font-size: 32px;
}
#a.pointer {
top: 43%;
left: 52%;
}
#b.pointer {
bottom: 5%;
left: 52%;
}
.box {
width: 600px;
height: 450px;
position: relative;
}
.spacer {
position: relative;
padding: .1% 0;
width: 2px;
}
code {
font-family: Consolas;
color: red;
}
<section class="box">
<figure>
<figcaption>object-fit: cover</figcaption>
<img class="bg1" src="http://img.youtube.com/vi/MzMqjG9om18/hqdefault.jpg" />
</figure>
<figure>
<figcaption>object-fit: contain</figcaption>
<img class="bg2" src="http://img.youtube.com/vi/MzMqjG9om18/hqdefault.jpg" />
</figure>
<figure>
<figcaption>Without anything but the height property</figcaption>
<img class="bg3" src="http://img.youtube.com/vi/MzMqjG9om18/hqdefault.jpg" />
</figure>
<aside>
<p><code>object-fit: cover</code> will stretch an image to the edges of it container (parent element) while keeping aspect ratio and cropping.</p>
<p>But when given the correct dimensions, <code>object-fit: cover</code> will result in a perfect fit edge to edge. No cropping either.</p>
<div class="spacer"> </div>
<p><code>object-fit: contain</code> will stretch an image to the edges of it container while keeping aspect ratio but will not crop at the edges, so as you can see, this image has space left and right. At wider dimentions, the space will manifest below and above.</p>
<div class="spacer"> </div>
<p>This is the image when set to it aspect ratio at 270 x 152px and as you can see, without <code>object-fit:cover</code>, math alone will not resolve the problem.</p>
</aside>
</section>
Hide result