gpt4 book ai didi

html - CSS 中的宽度无法正常工作

转载 作者:行者123 更新时间:2023-11-28 04:20:05 26 4
gpt4 key购买 nike

所以我的提交按钮出现了一个非常奇怪的问题。我在提交按钮上使用 width:100%,它处于“包装”状态 所以,基本上它应该是全宽,但最终我似乎无法让它工作.这是我正在谈论的内容的屏幕截图

enter image description here

如您所见,输入字段在 width:100% 下都可以正常工作,但提交不工作。这是相应问题的代码。

HTML 部分。

<div class="wrap">
<form>
<div>
<input type="text" placeholder="Name">
</div>
<div>
<input type="text" placeholder="Email">
</div>
<div>
<input type="password" placeholder="Password">
</div>
<div>
<input type="submit">
</div>
</form>
</div>

还有它的 CSS。

input[type=submit] {
font-family: "Avenir", "Helvetica Neue", Helvetica, Arial, sans-serif;
display: block;
height: 52px;
width: 100%;
margin: 0 auto;
background: #27A6D1;
text-align: center;
color: #fff;
line-height: 52px;
font-size: 20px;
font-weight: 500;
cursor: pointer;
padding: 0;
border: none;
}
.wrap {
width: 320px;
margin: 0 auto;
padding: 40px 0;
}
input {
width: 100%;
height: 52px;
margin: 0 0 10px;
font-size: 18px;
font-family: "Avenir", "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #333;
background: #fff;
padding: 0 14px;
outline: none;
border: 1px solid #ccc;
}

我可以让它与 width: 109% 一起工作,但我更喜欢使用 100,并说明为什么这不起作用,伙计们有什么想法吗?

此外,find a fiddle here .

最佳答案

一个快速修复方法是在表单中的所有输入元素上使用 box-sizing: border-box,然后声明一个统一的宽度:这将确保宽度被计算为最终边框-框宽度(包括边框宽度和填充)。

input {
box-sizing: border-box;
width: 100%;
}

然后您可以安全地为每个单独的输入元素自定义填充(如果您愿意的话),而不必担心它们会如何影响元素的最终宽度。

这是根据您提供的标记构建的概念验证 fiddle ;) http://jsfiddle.net/teddyrised/kx39z/

关于html - CSS 中的宽度无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23481811/

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