我得到了一个带有很多标签+输入的html
<label>Application</label>
<input id="ApplicationName" />
...
<label>Foo</label>
<input id="Foo" />
...
<label>Junk</label>
<input id="Junk" />
我强制宽度以增加一些一致性
label {
display: inline-block;
width: 10em;
}
input {
width: 10em;
}
使用这种样式会好一些,但是根据容器的宽度,流程仍然会“随处”中断。如何使标签+输入成为一个 block ? (没有将它们都封装在一个容器中)
另一个可接受的解决方案是
add a virtual carriage return after each input或者
before each label .
没成功放after是因为input标签不支持after。
我也不能把它放在前面因为
label::before {
content: "\A";
white-space: pre;
}
不能很好地与标签{display:inline-block} 混合
label {
display:inline-block;
width:10em;
}
input {
width:10em;
}
<div>
<label>namespace</label>
<input id="namespace" />
<label>Application</label>
<input id="application" />
<label>Description</label>
<input id="Description" />
<label>Author</label>
<input id="Author" />
</div>
resize the window to exhibit unwanted behaviour
最佳答案
你可以混合使用 float 和清除,有点老派但似乎对结构有效:
label {
display: block;
width: 10em;
float: left; /* makes the element act like inline block */
clear: left; /* clears any left floats so before so this should start on new line */
}
input {
width: 10em;
float: left;
}
<div>
<label>namespace</label>
<input id="namespace" />
<label>Application</label>
<input id="application" />
<label>Description</label>
<input id="Description" />
<label>Author</label>
<input id="Author" />
</div>
或者你可以给你的父容器一个宽度来强制内容到下一行:
div {
width: 21em;
}
label {
display: inline-block;
width: 10em;
}
input {
width: 10em;
}
<div>
<label>namespace</label>
<input id="namespace" />
<label>Application</label>
<input id="application" />
<label>Description</label>
<input id="Description" />
<label>Author</label>
<input id="Author" />
</div>
关于html - 仅使用 css 输入后换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47513036/