[英]How do I page center these left/right aligned label and form inputs?
I have this set (JsFiddle link) of labels and text inputs. 我有这组标签和文本输入(JsFiddle链接)。
How do I center the whole thing in the middle of the page? 如何将整个内容放在页面中间?
I tried wrapping them in a div and setting it's alignment to cetner - didn't do what i expected at all. 我尝试将它们包装在div中并将其对齐方式设置为cetner-完全没有达到我的期望。
Any help is appreciated, than you. 任何帮助都比您感激。
Code for reference: 参考代码:
<div>
<div class="left">
label
</div>
<div class="right">
input element
</div>
</div>
<div>
<div class="left">
another label
</div>
<div class="right">
another input element
</div>
</div>
//align the labels and input nicely
.left {
width: 20%;
float: left;
text-align: right;
}
.right {
width: 65%;
margin-left: 10px;
float:left;
}
If you're going to use float, than you need to wrap the whole thing in a DIV and apply margin: 0 auto;
如果要使用float,则需要将整个内容包装在DIV中并应用margin: 0 auto;
I'd do this in this case: 在这种情况下,我会这样做:
<style>
.field {
width: 80%;
margin: 0 auto;
}
.left {
width: 20%;
text-align: right;
display: block;
float: left;
margin-right: 5%;
}
</style>
<div class="field">
<label class="left">label</label>
<input type="text">
</div>
<div class="field">
<label class="left">another label</label>
<input type="text">
</div>
wrap the whole thing in a div and set 将整个内容包装在div中并设置
margin: auto;
also set a width, if you want to use the text-align: center;
如果您想使用text-align: center;
还要设置一个宽度text-align: center;
method , that should be applied to the parent pf the div to be centered. 方法,应将其应用于要居中的div的父对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.