I have a parent
div that contains an absolute positioned child
div.
The child
div is positioned outside the initial boundaries of parent
div. It was rendering normally without any problems.
I added an overflow-y: scroll;
to the parent
div, and now the child
element is hidden despite adding overflow-x: visible;
.
CSS
#parent{
position: relative;
overflow-y: scroll;
overflow-x: visible;
}
#child{
position: absolute;
left: -50px;
}
Also a Fidle
To hide the horizontal scrollbar and prevent horizontal scrolling, use overflow-x: hidden: HTML.
To change this, set the min-width or min-height property.” This means that a flex item with a long word won't shrink below its minimum content size. To fix this, we can either use an overflow value other than visible , or we can set min-width: 0 on the flex item.
The overflow-y property specifies whether to clip the content, add a scroll bar, or display overflow content of a block-level element, when it overflows at the top and bottom edges.
The content renders outside the element's box. hidden - The overflow is clipped, and the rest of the content will be invisible. scroll - The overflow is clipped, and a scrollbar is added to see the rest of the content. auto - Similar to scroll , but it adds scrollbars only when necessary.
Well found this on stackoverflow, but you aren't going to be happy.
CSS overflow-x: visible; and overflow-y: hidden; causing scrollbar issue
To put it short the answer says this
If you are using
visible
for eitheroverflow-x
oroverflow-y
and something other thanvisible
for the other. Thevisible
value is interpreted asauto
.
His answer goes more in depth talking about the W3 spec which explains this occurrence.
Pretty much your overflow-x
can't be visible because it will turn to auto
. (which part of that style hides the content that goes out of it.) if your overflow-y
is anything different from it.
EDIT:
You could try this however as a workaround for that spec.
HTML
/*Necessary styles for example*/
#parent{
display: inline-block;
position: relative;
}
#absolute-child {
position: absolute;
left: -50px;
}
#child{
overflow-y: scroll;
}
/*Below here is styles only for display purposes*/
body {
display:flex;
justify-content: center;
}
#absolute-child {
background-color: red;
color: white;
}
#child{
border: solid 1px black;
width: 200px;
height: 200px;
overflow-y: scroll;
}
#child {
border: solid 1px black;
width: 200px;
height: 200px;
}
<div id=parent>
<div id=absolute-child>
This is the child
</div>
<div id=child>
This is the child
</div>
</div>
http://jsfiddle.net/BFLQr/
Give me a second to explain what I did.
EDIT
So first of all I basically had to move your parent div to be a child div of the parent div that is now there. This is a little strange, but it's the only thing I could think of. The now parent div has the "shrink to fit" style applied to it through display: inline-block
this wraps it around it's child divs.
Since position absolute
gets pushed out of the document flow this means your absolute
position child does not affect the width or height of it's new "shrink to fit" parent. The "shrink to fit" parent also has display relative
this let's your absolute
position div be positioned according to it. Also since the parent is now display inline-block
in order to center it you must use text-align center
on it's containing element. which means you also need to put text align left
on your #parent or #child elements.
Hope this helped. :)
P.S. I edited the fiddle it had an unnecessary position relative on the #child element. I also added the text-align left to the new parent
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With