Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to zoom div on hover in percent

Tags:

html

css

i want that the zoom-in will effect only the img inside the div and won't resize all the div scale

here is the fiddle link: http://jsfiddle.net/4tHWg/1/

example code:

.box {
   float: left;
   position: relative;
   width: 14.285714286%;



}

.boxInner img {
   width: 100%;
   display: block;
   -webkit-filter: grayscale(00%);
   -moz-filter: grayscale(00%);
   -o-filter: grayscale(00%);
   -webkit-transition: all 1s ease;
     -moz-transition: all 1s ease;
   -o-transition: all 1s ease;
  -ms-transition: all 1s ease;
      transition: all 1s ease;

}

.boxInner img:hover {
  width: 200%;
}
like image 792
alonblack Avatar asked Nov 10 '13 00:11

alonblack


People also ask

How do you zoom in on hover?

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.

How do you scale up on hover?

Try moving your mouse over this box: It scales up exactly 1.5 times the original size — so it becomes 50% bigger when you move your mouse over (hover) it. The CSS transform property's scale method can either increase or decrease the size of elements.

How do I hover in a div?

The :hover selector is used to select elements when you mouse over them. Tip: The :hover selector can be used on all elements, not only on links. Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :active selector to style the active link.

What is * Zoom in CSS?

The zoom property in CSS allows you to scale your content. It is non-standard, and was originally implemented only in Internet Explorer. Although several other browsers now support zoom, it isn't recommended for production sites.


2 Answers

You can use css transforms:

http://jsfiddle.net/4tHWg/3/

.boxInner img:hover {      
  -webkit-transform: scale(1.4);
  -moz-transform: scale(1.4);
  -ms-transform: scale(1.4);
  -o-transform: scale(1.4);
  transform: scale(1.4);    
}

1.4 equals 1.4 times its original size.

like image 95
hugo der hungrige Avatar answered Oct 06 '22 15:10

hugo der hungrige


Adding on to hugo's answer, you should add this to your parent element.

.boxInner {
    overflow: hidden;
}

.boxInner img:hover {      
   -webkit-transform: scale(1.4);
   -moz-transform: scale(1.4);
   -ms-transform: scale(1.4);
   -o-transform: scale(1.4);
   transform: scale(1.4);    
}

This way the div won't resize together with the child image.

like image 21
JayC Ker Avatar answered Oct 06 '22 15:10

JayC Ker