Reputation: 2123
HTML
<div class="wrapper">
<div class="parent">
<div class="child">
lorem ipsum
</div>
</div>
</div>
CSS
.wrapper {
width: 300px;
height: 300px;
margin: 30px auto;
border: 1px dashed #ccc;
overflow:hidden;
}
.parent {
width: 1px;
height: 100px;
background-color: #f00;
opacity: 0;
margin: 0 auto;
-webkit-transition: all 0.4s ease;
transition: all 0.4s ease;
}
.wrapper:hover .parent {
opacity: 1;
-webkit-transform: scaleX(300);
transform: scaleX(300);
}
.wrapper . parent .child {
-webkit-transform: none;
transform: none;
}
I want to scale only .parent element when hovering .wrapper div. But it also affects two div (parent and child) although give transform:none property for .child div. How do I prevent .child affected?
http://jsfiddle.net/cdmkoao4/1/
Upvotes: 4
Views: 4307
Reputation: 911
Instead of transform: scaleX
try changing the width
.wrapper:hover .parent {
opacity: 1;
width: 100%;
}
http://jsfiddle.net/cdmkoao4/3/
Update:
Honestly, I don't see any reason why would you use scaleX
instead of width
, but this is the only solution that I came up with. Simply don't nest .child
with .parent
, make them separate divs with position: absolute
. On hover, you'd scaleX
only .parent
, while you'd only change the opacity
of .child
(I still used same classes even though they don't have parent-child
status anymore).
http://jsfiddle.net/cdmkoao4/9/
You'd need to play a bit with transition-delay
time to get the exact effect you want.
Upvotes: 5