Reputation: 606
I have a div which I want to move on hover. However, everything below this div also moves. I only want the div class="plantools" to move on hover and not everything else underneath it. How do I stop this from happening. Please see the fiddle here.
HTML:
<div id="home-plantools-col">
<div class="plantools">
<p>content</p>
</div>
</div>
<div id="homemidcontent">
<div id="home-dir-left">Test</div>
</div>
CSS:
#home-plantools-col {
width:20%;
padding:5px;
}
.plantools {
background: red;
-webkit-transition: margin 0.2s ease-out;
-moz-transition: margin 0.2s ease-out;
-o-transition: margin 0.2s ease-out;
}
.plantools:hover {
margin-top: -10px;
}
Upvotes: 0
Views: 105
Reputation: 1436
I personally think it is far easier to use
.plantools {
background: red;
position:relative;
-webkit-transition: top 0.2s ease-in-out;
-moz-transition: top 0.2s ease-in-out;
-o-transition: top 0.2s ease-in-out;
}
.plantools:hover {
top:-10px;
}
I used ease-in-out
just because I like it better, but you can still use ease-out
Upvotes: 0
Reputation: 61
Simply add "position:relative" to .plantools and change "margin-top:-10px" by "top:-10px" in .plantools:hover.
This way, the element will be moved up but will keep the same position in the flow.
Here is the updated css :
#home-plantools-col {
width:20%;
padding:5px;
}
.plantools {
position:relative;
background: red;
-webkit-transition: margin 0.2s ease-out;
-moz-transition: margin 0.2s ease-out;
-o-transition: margin 0.2s ease-out;
}
.plantools:hover {
top: -10px;
}
Upvotes: 0
Reputation: 20102
A nasty dirty way to do it,if you know the heigth it will take, is by using a wrap div:
<div id="wrapper">
<div id="home-plantools-col">
<div class="plantools">
<p>content</p>
</div>
</div>
</div>
and set the wrap's height to something fixed:
Upvotes: 0
Reputation: 16777
Use transform
instead of margin
.plantools {
-webkit-transition: transform 0.2s ease-out;
-moz-transition: transform 0.2s ease-out;
-o-transition: transform 0.2s ease-out;
transition: transform 0.2s ease-out;
}
.plantools:hover {
-webkit-transform: translateY(-10px);
-ms-transform: translateY(-10px);
transform: translateY(-10px);
}
transform
holds some browser support issues, but so does using transitions
and you're already using it.Upvotes: 1