gpt4 book ai didi

html - 如何在父div中包含文本框

转载 作者:可可西里 更新时间:2023-11-01 13:10:25 26 4
gpt4 key购买 nike

following HTML/CSS example ,文本框超出了 div 的边界。尽管输入是 display:block 并且宽度为 100%,但我希望文本框保留在 div 中。

为什么不留在父容器中?我怎样才能修复它,使其响应并保持在父边框中?

<div class="first">
<input type="text" value="not working" />
</div>

<br/>
<br/>
<div class="sec">
<input type="text" value="not working" />
</div>

<br/>
<div class="second">
<span class="second-wrap">
expected layout with text box
</div>
</div>

div.first{
width:50%;
border:3px solid black;
}

div.first input{
display:block;
padding:20px;
border:3px solid blue;
}

.sec{
width:50%;
border:3px solid black;
}

.sec input{
display:block;
width:100%;
padding:20px;
border:3px solid blue;
}

div.second{
border:3px solid red;
width:50%;
}
.second-wrap{
border:3px solid blue;
display:block;
padding:20px;
}

最佳答案

如果您设置box-sizing: border-box,您将添加边框和填充到全宽。

在输入 CSS 上使用这些更改

  -webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
max-width: 100%;

参见 this codepen

关于html - 如何在父div中包含文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23993802/

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