Liga
Liga

Reputation: 3439

CSS ignores margin-right when the div is longer than 100%

I have a div that stretches longer than 100%. I am trying to create a container div around it but when I set the margin left and right to 50% the container div doesn't even seem to stretch all the way. It sort of works for the smaller div but it doesn't work for the longer div.

The margin-left seems to work fine but on the right side of the first div there is no margin.

<html>

<body>
  <div style="margin: 50px 50px; padding-right: 40px;">
    <div style="white-space: nowrap; font-size: 12px;font-weight: 600;text-transform: uppercase;color: #7a7a7a;background: #dedede;border-radius: 3px 3px 0px 0px;font-family:;display: inline-block;min-width: 100%;">
      <div style="display: flex; flex-wrap: nowrap">
        <div>oneon e saf </div>
        <div> </div>
        <div style="width: 10px; margin: 0 100px; white-space: normal;">This is a div heheheh</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
      </div>
    </div>

    <div style="background-color: gray; margin-top: 10px;">This is another div</div>
  </div>
</body>

</html>

Here is a scratchpad fiddle http://scratchpad.io/foregoing-mitten-6881

Upvotes: 0

Views: 74

Answers (4)

Vincent Reynier
Vincent Reynier

Reputation: 40

Maybe like that

<html>

    <body>
        <div style="margin: 50px 50px; padding-right: 40px;">
            <div style="white-space: nowrap; font-size: 12px;font-weight: 600;text-transform: uppercase;color: #7a7a7a;background: #dedede;border-radius: 3px 3px 0px 0px;font-family;">
                <div>oneon e saf </div>
                <div> </div>
                <div style="width: 10px; margin: 0 100px; white-space: normal;">This is a div heheheh</div>
                <div>oneon e saf </div>
                <div> </div>
                <div>This is a div</div>
                <div>oneon e saf </div>
                <div> </div>
                <div>This is a div</div>
                <div>oneon e saf </div>
                <div> </div>
                <div>This is a div</div>
                <div>oneon e saf </div>
                <div> </div>
                <div>This is a div</div>
                <div>oneon e saf </div>
                <div> </div>
                <div>This is a div</div>
                <div>oneon e saf </div>
                <div> </div>
                <div>This is a div</div>
                <div>oneon e saf </div>
                <div> </div>
                <div>This is a div</div>
                <div>oneon e saf </div>
                <div> </div>
                <div>This is a div</div>
                <div>oneon e saf </div>
                <div> </div>
                <div>This is a div</div>
                <div>oneon e saf </div>
                <div> </div>
                <div>This is a div</div>
                <div>oneon e saf </div>
                <div> </div>
                <div>This is a div</div>
                <div>oneon e saf </div>
                <div> </div>
                <div>This is a div</div>
                <div>oneon e saf </div>
                <div> </div>
                <div>This is a div</div>
                <div>oneon e saf </div>
                <div> </div>
                <div>This is a div</div>
                <div>oneon e saf </div>
                <div> </div>
                <div>This is a div</div>
            </div>

            <div style="background-color: gray; margin-top: 10px;">This is another div</div>
        </div>
    </body>

</html>

Upvotes: 0

sstavridis
sstavridis

Reputation: 46

By default, flex items will all try to fit onto one line. You can change that and allow the items to wrap as needed with this property.

Try to use flex-wrap: wrap source: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Upvotes: 0

Sai Manoj
Sai Manoj

Reputation: 3859

Apply display:inline-block to the parent div

<html>

<body>
  <div style="padding: 40px;margin: 50px 50px;display:inline-block">
    <div style="white-space: nowrap; font-size: 12px;font-weight: 600;text-transform: uppercase;color: #7a7a7a;background: #dedede;border-radius: 3px 3px 0px 0px;font-family:;display: inline-block;min-width: 100%;">
      <div style="display: flex; flex-wrap: nowrap">
        <div>oneon e saf </div>
        <div> </div>
        <div style="width: 10px; margin: 0 100px; white-space: normal;">This is a div heheheh</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
      </div>
    </div>

    <div style="background-color: gray; margin-top: 10px;">This is another div</div>
  </div>
</body>

</html>

Upvotes: 2

Lalji Tadhani
Lalji Tadhani

Reputation: 14169

Add this CSS Your container div overflow:auto;

<html>

<body>
  <div style="margin: 50px 50px; padding-right: 40px; overflow:auto;">
    <div style="white-space: nowrap; font-size: 12px;font-weight: 600;text-transform: uppercase;color: #7a7a7a;background: #dedede;border-radius: 3px 3px 0px 0px;font-family:;display: inline-block;min-width: 100%;">
      <div style="display: flex; flex-wrap: nowrap">
        <div>oneon e saf </div>
        <div> </div>
        <div style="width: 10px; margin: 0 100px; white-space: normal;">This is a div heheheh</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
        <div>oneon e saf </div>
        <div> </div>
        <div>This is a div</div>
      </div>
    </div>

    <div style="background-color: gray; margin-top: 10px;">This is another div</div>
  </div>
</body>

</html>

Upvotes: 0

Related Questions