有很多方法可以做到这一点。选择最适合您项目的产品。我将使用CSS将标签和包含输入的div设置为“inline”或“inline-block”。然后,如果您需要将行分解为两部分,请使用媒体查询(请参阅最后一段代码片段)。
<h4>Company Details</h4>
<div class="input-group">
<label for="company">Company</label>
<div>
<input type="text" name="company" value="<?php echo $customer["company"]; ?>" />
</div>
</div>
// This will make them show inline occupying half the width
.input-group > label, .input-group > div{
display: inline-block;
width: 50%;
}
我有时与直列块, 额外的像素问题,我通常由浮动块或 字体大小设置为零解决它。
// This way the label and input float
.input-group {
clear: both; // So the container doesn't collapse
}
.input-group > label, .input-group > div{
float: left;
width: 50%;
}
字体大小的版本:
// This way the font size in the container is zero
.input-group {
font-size: 0;
}
.input-group > label, .input-group > div{
display: inline-block;
width: 50%;
font-size: 12px;
}
你div
会自动延伸到屏幕的100%,所以你不需要媒体查询来设置它的宽度;它已经是响应了。但是,如果你坚持使用它们,或者需要它们,请添加以下内容:
@media (max-width: 500px) {
.input-group > label, .input-group > div{
display: block;
float: none;
}
}
来源
2015-04-17 12:47:44
ecc
您使用的引导? http://getbootstrap.com/css/#grid –
@ K.B.M bootstrap与什么有关? – Rob
是的,为什么不使用整个框架来替换两行CSS? – ecc