I have a horizontally scrolling div that has a left and right padding of 100px. The left padding seems to be working fine. However, the right side is not visible. What's more, the 50px right margin on the last section is also missing.
What am I missing? Why are both the right padding and margin not respected?
body {
margin: 0;
}
div {
width: 100vw;
display: flex;
overflow: auto;
padding: 0 100px;
box-sizing: border-box;
}
section {
flex: 0 0 auto;
width: 300px;
margin: 0 15px;
height: 300px;
background: red;
}
<div>
<section></section>
<section></section>
<section></section>
</div>
Update
Per @chaitanya swami's suggestion, the following is a workaround. I'm still wondering why the above doesn't work as expected.
body {
margin: 0;
}
#wrapper {
width: 100vw;
overflow: auto;
}
#carousel {
display: flex;
padding: 0 100px;
width: calc(100vw + 400px);
}
.slide {
flex: 0 0 auto;
width: 300px;
margin: 0 15px;
height: 300px;
background: red;
}
<div id="wrapper">
<div id="carousel">
<section class="slide"></section>
<section class="slide"></section>
<section class="slide"></section>
</div>
</div>