gpt4 book ai didi

html - 当 div 超过 100% 时,CSS 会忽略 margin-right

转载 作者:太空宇宙 更新时间:2023-11-04 00:46:07 25 4
gpt4 key购买 nike

我有一个拉伸(stretch)超过 100% 的 div。我正在尝试围绕它创建一个容器 div,但是当我将左右边距设置为 50% 时,容器 div 似乎并没有一直延伸。它适用于较小的 div,但不适用于较长的 div。

margin-left 似乎工作正常,但在第一个 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>

这是一个暂存器 fiddle http://scratchpad.io/foregoing-mitten-6881

最佳答案

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>

关于html - 当 div 超过 100% 时,CSS 会忽略 margin-right,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57110052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com