Reduce image and center

Asked

Viewed 392 times

2

I have an image that I bring from the database and put an IMG tag in the size of 960px by 480px. I need to resize it to 470x160. I need it to be resized by the length and the leftover height to be cropped, but taking it out from the center. See the image below:

inserir a descrição da imagem aqui

I need to dispose of the two gray bands.

Can you do this in CSS3 or Jquery? If so, how?

Thank you

2 answers

1


Hello,
take a look at this link to see if this was the desired result.
this is the code:

$("img").hover(function(){
    $(this).toggleClass("img-zoom");
});
div{
    position: relative;
    overflow:hidden;
    width:470px;
    height:160px;
}
img{
    position: relative;
    top: -50%;
    margin-top: 40px;
    width:100%;
    -webkit-transition: all .1s ease-in-out; -moz-transition: all .1s ease-in-out; -o-transition: all .1s ease-in-out; -ms-transition: all .1s ease-in-out;
}
.img-zoom { -webkit-transition: all .1s ease-in-out; -moz-transition: all .1s ease-in-out; -o-transition: all .1s ease-in-out; -ms-transition: all .1s ease-in-out; -webkit-transform: scale(1.2); -moz-transform: scale(1.2); -o-transform: scale(1.2);     transform: scale(1.2); 
}
<div>
    <img src="http://i.stack.imgur.com/sKByS.jpg" alt="img" />
</div>

  • That’s right. Thank you

  • You’re welcome, I hope I helped.

1

One solution would be to use the statement transform in the image:

div{
    position: relative;
    overflow:hidden;
    width:470px;
    height:160px;
}
img{
    position: relative;
    top: 50%;
    transform: translateY(-50%);
    width:100%;
}
<div>
    <img src="http://i.stack.imgur.com/sKByS.jpg" alt="img" />
</div>

This way, you have a container for the image that defines the width and height you want to get.

The image is the width of that container, the declaration transform will center the image on that container and the image top/bottom is hidden because the container has the overflow hidden.

  • look worked in parts. When I apply these 2 css they work right but I have an event and Hover in Jquery that zooms in on the image it applies the following CSS when you hover over the image: .img-zoom {&#xA; -webkit-transition: all .1s ease-in-out;&#xA; -moz-transition: all .1s ease-in-out;&#xA; -o-transition: all .1s ease-in-out;&#xA; -ms-transition: all .1s ease-in-out;&#xA;} and when you leave Active Hotel this class: .transition-zoom {&#xA; -webkit-transform: scale(1.2);&#xA; -moz-transform: scale(1.2);&#xA; -o-transform: scale(1.2);&#xA; transform: scale(1.2);&#xA;}.

  • This will stop if I remove the top: 50%; Transform: translateY(-50%); width: 100%; it will work again. Can you make the 2 run together? Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.