有很多方法可以做到這一點。選擇最適合您項目的產品。我將使用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