Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CSS, how do you create larger elements when the mouse is over them?

The effect seen is that the boxes increase in size when the mouse is over them, and there is a drop shadow too.

When the mouse is not over the boxes, they go back to the same size with no drop shadow.

Normal:

enter image description here

Mouse over:

enter image description here

Scroll over the boxes to see the effect here.

like image 595
user1943906 Avatar asked Jan 02 '13 22:01

user1943906


People also ask

How do you make things bigger when hovering CSS?

zoom-box:hover we add the transform property, with the scale() method as a value. It takes a parameter 1.5 which is what dictates how much the box element should scale up on hover. 1.5 is like saying 150% of the original size.

How do you make elements bigger in CSS?

You can use the CSS zoom property to scale any HTML element. Note that it does not work in Firefox, you could use -moz-transform: scale(NUMBER); instead (and if you go that route, you can use transform: scale(NUMBER); on all browsers, too).

How do you affect other elements when one element is hovered CSS?

Approach: This task can be accomplished by adding one element inside the other element & accordingly declaring the required CSS properties for the parent-child elements, so that whenever hovering outside the element then automatically the property of the inner element will change.


1 Answers

jsFiddle DEMO

Hovering over elements and making them larger can be done in many ways, and it depends on your layout requirements and the framework your using.

Since those boxes appear to be div's with CSS3 box shadow property, you can do something like that in pure CSS using :hover

HTML:

<div class="box">1</div>
<div class="box">2</div>
<div class="box">3</div>

CSS:

body {
  background-color: black;
}

.box {
  background-color: grey;
  width: 200px;
  height: 400px;
  float: left;
  border: 6px solid red;
  margin: 10px;
}

.box:hover{
  width: 250px;
  /* This is 52px total. 1/2 of that is for top and the other half is for bottom. */
  height: 452px;
  /* Below we are not using -26px for margin-top because .box has 6px border and 10px margin. */
  /* That 16px is then divide by 2 since it's for both top and bottom, or 8px per side. */
  /* Having said that, 26px - 8px is 18px. We need negative value to position it correctly. */
  margin-top: -18px;
 -moz-box-shadow:    0 0 50px red;
 -webkit-box-shadow: 0 0 50px red;
 box-shadow:         0 0 50px red;    
}

EDIT 2:

Revised jsFiddle DEMO

enter image description here

like image 50
arttronics Avatar answered Sep 21 '22 15:09

arttronics