0

I have a scenario where the child elements inside Flexbox div should be nowrap and then scroll horizontally if the child items exceeds the maximum allowed space.

Please check the link: https://www.w3schools.com/code/tryit.asp?filename=FY50HW0O11JZ

As you can see in the above link the space over the right side is eliminated.

enter image description here

How can I include the padding/margin space of parent div or child div while using horizontal scrolling?

Thanks in advance!

Georgi Hristozov
  • 3,899
  • 2
  • 17
  • 23
Harikrishnan N
  • 874
  • 1
  • 10
  • 19

1 Answers1

1

If you wrap the white boxes in an another div with display flex and apply padding-right for that div, you will have the space at the end.

<!DOCTYPE html>
<html>
    <head>
        <style>
            .a {
                display: flex;
                flex-direction: row;
                overflow-x:auto;
                background: yellow;
            }
            .a1 {
                min-width: 300px;
                border: 1px solid;
                background: white;
                flex: 0 0 auto;
                overflow:auto;
            }
        </style>
    </head>
    <body>

    <div class="a" style="max-width: 500px; border: 1px solid; padding: 30px;">
            <div style="display: inherit">
                <div class="a1">a</div>
                <div class="a1">b</div>
                <div class="a1">c</div>
            </div>
        </div>
    </body>
</html>