Reputation: 45
When I resize my image with the :hover property it does get larger, but it resizes from the left and out, instead of from the center and out...
My code HTML:
<a href=""><img src="cover (1).jpg"class="cover"><a>
<a href=""><img src="cover (2).jpg"class="cover"><a>
<a href=""><img src="cover (3).jpg"class="cover"><a>
<a href=""><img src="cover (4).jpg"class="cover"><a>
CSS:
img.cover{
height:100px;
Width:100px;
padding-top:25px;
position:relative;
left:290px;
}
img.cover:hover {
height:150px;
width:150px;
margin-top:-25px;
vertical-align:top;
position:relative;
-webkit-transition: 2s; /* Safari and Chrome */
}
Upvotes: 1
Views: 3729
Reputation: 855
If you know in all instances what the dimensions of your images are going to be, you can accomplish this by displaying the image as a block element and changing the padding as well as dimensions on hover.
CSS:
a img {
display: block;
width: 100px;
height: 100px;
padding: 25px;
background-color: red;
}
a img:hover {
width: 150px;
height: 150px;
padding: 0;
}
HTML:
<a href=""><img src="" /></a>
<a href=""><img src="" /></a>
<a href=""><img src="" /></a>
Here is a demo on jsfiddle:
Upvotes: 1
Reputation: 1237
Try this, maybe this is the effect you want to achieve...
img.cover:hover {
margin-left: -25px;
margin-right: -25px;
}
Upvotes: 1
Reputation: 109
You'll need to adjust the left
and top
properties in your .hover
css. Try:
left:-25px;
right:-25px;
Upvotes: 0