Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move link image 5px up on hover

Tags:

How would I go about acheiving an effect similar to that on this site's portfolio page Solid Giant, with CSS and HTML?

I had thought that just putting something like this would work:

a img{     margin-top: 5px; }  a img:hover{     margin-top: 0px; } 

But it did not work, even if I put the :hover on the link instead of the img. I scoured his code and css but I could not for the life of me figure this out. Help please :)

like image 698
Amanda Avatar asked Mar 27 '11 11:03

Amanda


People also ask

How do I change the hovering image in HTML?

Answer: Use the CSS background-image property You can simply use the CSS background-image property in combination with the :hover pseudo-class to replace or change the image on mouseover.

Which style rule would make the image 50% smaller during a hover?

Answer: Use the CSS transform property You can use the CSS transform property to increase or decrease the image size on mouse hover without affecting the surrounding elements or content.


2 Answers

position: relative would work:

a img:hover{ position: relative;               top: -5px;}  

note that position: relative reserves the space in the document flow as if the element were not moved. But I think in this case, that is not an issue.

like image 57
Pekka Avatar answered Dec 04 '22 13:12

Pekka


Also see translate():

http://www.w3schools.com/css/css3_2dtransforms.asp

img:hover {     -moz-transform: translate(-2px, -2px);     -ms-transform: translate(-2px, -2px);     -o-transform: translate(-2px, -2px);     -webkit-transform: translate(-2px, -2px);     transform: translate(-2px, -2px) } 

See a similar working example:
http://jsfiddle.net/rimian/7aPvS/1/

like image 22
Rimian Avatar answered Dec 04 '22 13:12

Rimian