Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mouse hover change image position and size

Tags:

html

css

hover

I'm trying to do a button menu for my web site and I have an issue with the position of the image on mouse hover. This is what I have created so far http://jsfiddle.net/tNLUx/

On mouseover, I want the selected image to grow and the other ones keep their same position just like the first image... how do I make the down images to grow and move down instead of moving up?

#btnSocial {
  width:100px;
  position: relative;
  opacity: 0.5;
  -webkit-opacity: 0.5;
  -moz-opacity: 0.5;
  transition: 0.5s ease;
  -webkit-transition: 0.5s ease;
  -moz-transition: 0.5s ease;
}
#btnSocial:hover{
  width: 150px;
  opacity: 1;
  -webkit-opacity: 1;
  -moz-opacity: 1;
}
<img src="http://img24.imageshack.us/img24/3221/32845401.png" alt="img1" id="btnSocial" class="social1" />
<img src="http://img24.imageshack.us/img24/3221/32845401.png" alt="img1" id="btnSocial" class="social2"/>
<img src="http://img24.imageshack.us/img24/3221/32845401.png" alt="img1" id="btnSocial" class="social3"/>
<img src="http://img24.imageshack.us/img24/3221/32845401.png" alt="img1" id="btnSocial" class="social4"/>
like image 730
iniestar Avatar asked Feb 20 '13 03:02

iniestar


People also ask

How do I change the image on my mouse hover?

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.

How do you enlarge an image when hover over?

Zoom images/videos on all your favorite websites (Facebook, Amazon, etc). Simply hover your mouse over the image to enlarge it. Hover your mouse over any image on the supported websites and the extension will automatically enlarge the image to its full size, making sure that it still fits into the browser window.

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

Answer: Use the CSS transform property.


2 Answers

Use transform: scale(x, y) to scale the object.
Use transform: translate(x, y) to move the object.
Those two properties can also be combined: transform: scale(x, y) translate(x, y).

Example:

.btn-social {
    width: 100px;
    position: relative;
    opacity: 0.5;
    transition: 0.3s ease;
    cursor: pointer;
}

.btn-social:hover {
    opacity: 1;

    /** default is 1, scale it to 1.5 */
    transform: scale(1.5, 1.5);

    /** translate 50px from left, and 40px from top */
    /** transform: translate(50px, 40px); */

    /** combine both scale and translate */
    /** transform: scale(1.5, 1.5) translate(50px, 40px); */
}
<img src="http://sstatic.net/stackexchange/img/logos/so/so-icon.png?v=c78bd457575a" class="btn-social" />
<img src="http://sstatic.net/stackexchange/img/logos/so/so-icon.png?v=c78bd457575a" class="btn-social" /><br />
<img src="http://sstatic.net/stackexchange/img/logos/so/so-icon.png?v=c78bd457575a" class="btn-social" />
<img src="http://sstatic.net/stackexchange/img/logos/so/so-icon.png?v=c78bd457575a" class="btn-social" />
like image 197
novalagung Avatar answered Sep 16 '22 15:09

novalagung


Check this http://jsfiddle.net/tNLUx/11/

Removed position: relative; from css

#btnSocial{
    width:100px;
    opacity: 0.5;
    -webkit-opacity: 0.5;
    -moz-opacity: 0.5;
    transition: 0.5s ease;
    -webkit-transition: 0.5s ease;
    -moz-transition: 0.5s ease;

}
like image 43
999k Avatar answered Sep 20 '22 15:09

999k