Consider:
.overflow {
margin-left: 50px;
width: 100px;
height: 100px;
background: red;
}
.outer {
/*overflow-y: auto; */
width: 100px;
height: 200px;
border: 1px solid blue;
}
<div class="outer">
<div class="overflow">
</div>
</div>
This renders a red square (the .overflow
) that horizontally overflows the blue rectange (.outer
), as expected.
Now when I now uncomment overflow-y: auto;
, then I expect this to only affect vertical overflow, and thus I expect the red square to keep overflowing horizontally.
However, that's not what happens:
.overflow {
margin-left: 50px;
width: 100px;
height: 100px;
background: red;
}
.outer {
overflow-y: auto;
width: 100px;
height: 200px;
border: 1px solid blue;
}
<div class="outer">
<div class="overflow">
</div>
</div>
It seems that:
- Setting
overflow-x
has no effect on this (unset, visible, scroll, hidden - none of them work). - Setting
overflow-y
to anything other thanunset
triggers this behaviour
So my questions are:
- Why is that?
- How can I avoid this? I.e. how can I have
overflow-y: auto
, while still allowing horizontal overflow.