我将如何在输入元素上引发类似 div 的行为?具体来说,如何诱导宽度扩大,使其外部宽度(包括边距)填满容器?width: 100%
不起作用,因为它没有考虑其他盒子模型属性。
问问题
219 次
1 回答
1
我使用“hack”来解释输入边框宽度,如下所示......
<div>hello world</div>
<div class="adjustForTheInputBorder">
<input type="text" />
</div>
input
{
width:100%;
border-width:2px;
}
div.adjustForTheInputBorder
{
margin-right: 4px; /* or 2x whatever your input border width is */
}
div
{
background-color: pink;
}
我的adjustForTheInputBorder
班级往往有一个更恰当地表达我对 css 的仇恨的名字...... :)
PS默认div
呈现display:block
,你不需要在那里。
于 2010-08-06T14:57:32.393 回答