Reputation: 12679
For some reason, in an overflown container, the padding on the right side is not shown.
.parent {
background-color: orange;
width: 150px;
height: 50px;
overflow: auto;
padding-right: 15px;
}
.child {
background-color: blue;
width: 250px;
height: 100%;
margin: 0 10px;
}
body {
margin: 0;
padding: 0;
}
* {
box-sizing: border-box;
}
<div class="parent">
<div class="child">
</div>
</div>
I expected the orange color to show up when I scrolled to the very end (right)
Upvotes: 0
Views: 477
Reputation: 74
I have checked in also Mozilla Firefox. and it's working fine.
.parent {
background-color: orange;
width: 150px;
height: 50px;
overflow-y: hidden;
overflow-x: auto;
padding-right: 15px;
}
.child {
background-color: blue;
width: 250px;
height: 100%;
margin: 0 10px;
display: inline-block;
}
body {
margin: 0;
padding: 0;
}
* {
box-sizing: border-box;
}
<div class="parent">
<div class="child">
</div>
</div>
Upvotes: 1
Reputation: 273990
Let's start without applying any overflow
property. We clearly have the element outside of it's parent container (add padding of the container will remain inside):
.parent {
background-color: orange;
width: 150px;
height: 100px;
padding:15px;
}
.child {
background-color: blue;
width: 250px;
height: 100%;
}
body {
margin: 0;
padding: 0;
}
* {
box-sizing: border-box;
}
<div class="parent">
<div class="child">
</div>
</div>
Now by adding overflow:scroll
or overflow:auto
you will simply add the scroll to see the overflowing part and you won't have the padding as excepted:
.parent {
background-color: orange;
width: 150px;
height: 100px;
overflow:auto;
padding:15px;
}
.child {
background-color: blue;
width: 250px;
height: 100%;
}
body {
margin: 0;
padding: 0;
}
* {
box-sizing: border-box;
}
<div class="parent">
<div class="child">
</div>
</div>
Same logic with the margin right. When the element is overflowing there is no room to add margin between the inner element and the parent element.
Upvotes: 2
Reputation: 74
You should use below CSS. It's working for me.
.parent {
background-color: orange;
width: 150px;
height: 50px;
padding-right: 15px;
overflow-y: hidden;
overflow-x: auto;
}
.child {
background-color: blue;
width: 250px;
height: 100%;
margin: 0 10px;
display: inline-block;
}
Upvotes: 0