Option 1
Yes it is possible you can use the image as a background of a div that has the size you want. With the style background-position
vc sets the position of your background within the div in case it is centered horizontally and vertically to let the woman in the middle and cut the laterias as well
Look at the example. I did as you suggested, 800x1200
.imagem {
background-image: url(https://i.stack.imgur.com/4oeoT.jpg);
background-position: center;
background-size: cover;
width: 800px;
height: 1200px;
}
<div class="imagem"></div>
Option 2
Another option would be to put the style object-fit: cover
in the image, so it behaves as a background within the size you set in the tag img
But that’s not quite crossbrowser see here for support https://caniuse.com/#feat=Object-fit (in IE does not work)
See the example to better understand.
.imagem {
width: 800px;
height: 1200px;
object-fit: cover;
}
<img class="imagem" src="https://i.stack.imgur.com/4oeoT.jpg" alt="">
Option 3
You can put the image inside a div
with overflow:hidden
and use transform:translateX
to adjust it within the container in the desired position.
See the example. Here I decrease the size proportionally for you see that it does not deform. I left some comments on the code read.
.imagem {
width: 400px;
height: 600px;
overflow: hidden; /* esconde as laterais sobrando da imagem */
}
.imagem img {
transform: translateX(-14%); /* ajusta a imagem na horizontal na posição que vc quiser*/
height: 100%; /* deixa a imagem sempre com a altura correta */
}
<div class="imagem">
<img src="https://i.stack.imgur.com/4oeoT.jpg" alt="">
</div>
TIP: Although you do not see what was "cut" those sides that are hidden are part of the image file, then the weight of the image remains the same, and at the time of the request the file size will remain the same. Consider treating these images before using them on the site...
Guy edited again the answer with one more option, now has 3 ways for you to choose. Qq thing says there that I help you.
– hugocsl
@hugocslt old top, will help me enough your examples there! Thanks!
– Lucas de Carvalho
Quiet young, successful
– hugocsl