当div大于100%时,CSS会忽略右移边距

时间:2019-07-19 10:02:12

标签: html css

我的div的延伸时间超过100%。我正在尝试围绕它创建一个容器div,但是当我将左右边距设置为50%时,容器div似乎并没有完全伸展。这种方法适用于较小的div,但不适用于较长的div。

左边距似乎工作正常,但在第一个div的右侧没有边距。

<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>

这是便笺簿小提琴 http://scratchpad.io/foregoing-mitten-6881

4 个答案:

答案 0 :(得分:2)

display:inline-block应用于父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>

答案 1 :(得分:0)

也许是这样

<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>

答案 2 :(得分:0)

将此CSS添加到您的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>

答案 3 :(得分:0)

  

默认情况下,弹性项目将全部尝试放入一行。您可以对此进行更改,并允许该属性根据需要包装项目。

尝试使用flex-wrap:包装 来源:https://css-tricks.com/snippets/css/a-guide-to-flexbox/