Here is a jsFidle for the problem : https://jsfiddle.net/mvn0orto/
I have this HTML:
<div class="page state1"> <div class="navbar"></div> <div class="main"></div> </div> And I have this CSS:
.page{ width:200px; height:300px; background:red; position:relative; } .navbar{ position:absolute; left:0; right:0; top:0; height:60px; background:green; } .main{ position:absolute; top:70px; left:10px; right:10px; bottom:10px; background:blue; } .main:before{ content:'.main:before'; display:block; background:pink; height:50px; width:100px; position:absolute; top:0; transition-duration: 0.3s; } My .page can have 2 states, .state1 and .state2. And in function of the state, I'm applying a different translateY:
.state1 .main:before{ transform:translateY(0); } .state2 .main:before{ transform:translateY(-100%); } So, in .state2, my :before pseudoelement is outside the .main div.
The problem is: the .main div is in overflow:hidden, but it doesn't hide at all my :before element...
How could I achieve that? In the jsfiddle I provided at the beginning of the question, I want my pink square to disappear when it gets out of the .main div.
Thanks for your replies! :)
.maindoesn't haveoverflow:hidden- adding this seems to give the results that you want.mainis statically positioned.