In the following HTML structure (parent
> child
> grandchild
), the parent has the overflow:hidden;
property
<div id="parent">
<div id="child">
<div id="grandchild">
</div>
</div>
</div>
Can the grandchild
element override the parent’s overflow hidden?
My main concern are that
- the grandchild’s position is related to the child’s position.
- since the child’s position is related to the parent position, it has to move with the parent when scrolling.
- the grandchild’s styles (
font-size
,font-family
…) are inherited from the child.
The child must not be visible outside the parent, unlike the grandchild.
I already try many things. Nothing works and I start to wonder if what I want to do is possible.
In the following JSFiddle, the blue box should be half visible, but the green one should be fully visible.
2
Answers
UPDATE
The only drawback is that it does not solution does not support scrolling
In this update, we added a container to hold the children. We transform that container to the bottom of the parent, instead of using
#child
as the container. This snippet allows you to use your original code of transforms instead of usingbottom
.Fixed code not scrolling
With your current code, it does not seem possible. But if you changed your
#child
‘s code fromtransform: translateY(60px);
tobottom: -60px
and your#grandchild
toposition: fixed
, the code functions as you intended.If sizes and offsets of the elements are known, can be used
clip-path
insteadoverflow: hidden
.In the example below, entered something into css variables.
Or generate a
clip-path
using javascript, if each element is responsive: