gpt4 book ai didi

html - 主 div 内的元素超出宽度

转载 作者:太空宇宙 更新时间:2023-11-04 02:22:40 24 4
gpt4 key购买 nike

我将子元素 width 设置为 100%,但是 width 超过了 widthdiv

代码:

.MainFrame {
max-width: 750px;
height: auto;
margin: auto;
padding: 5px;
background-color: grey;
}
div.Status {
float: left;
width: 100%;
height: auto;
margin: 5px;
padding: 5px;
border: 3px solid;
}
div.Disclaimer {
float: left;
width: 100%;
height: auto;
margin: 5px;
padding: 5px;
border: 3px solid;
}
div.Settings {
float: left;
width: 100%;
height: auto;
margin: 5px;
padding: 5px;
border: 3px solid;
<div class="MainFrame">
<div class="Status">
<center>
<h1>Home Screen</h1>
</center>
<center>Waiting for a command from the user.</center>
</div>
<div class="Disclaimer">
<h3>This page will be used to direct user to other tools.</h3>
</div>
<div class="Settings">
<h2>Settings</h2>
<form method="post" action="/Download/">
<input type="submit" name="download" value="Download">
</form>
</div>
...
</div>

最佳答案

你的问题是属于盒子模型的 paddingborder 正在计算 100%

例如:width100% + padding 10px 会溢出。但是使用 box-sizing-border-box 可以解决这个问题,所以使用 box-sizing-border-box

你可以看到更多关于 box-sizing herehere

注意 center 标签已弃用,请勿使用它,改为使用 CSS 样式。

注意 2:我调整了您的 CSS,减少了重复的规则/属性。

*,
*:before,
*:after {
box-sizing: border-box;
}
body {
margin: 0
}
.MainFrame {
max-width: 750px;
height: auto;
margin: auto;
padding: 5px;
background-color: grey;
}
.MainFrame > div {
width: 98%;
margin: 5px;
padding: 5px;
border: 3px solid;
}
<div class="MainFrame">
<div class="Status">
<h1>Home Screen</h1>
Waiting for a command from the user.
</div>
<div class="Disclaimer">
<h3>This page will be used to direct user to other tools.</h3>
</div>
<div class="Settings">
<h2>Settings</h2>
<form method="post" action="/Download/">
<input type="submit" name="download" value="Download">
</form>
</div>
...
</div>

关于html - 主 div 内的元素超出宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37869857/

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