左对齐标签 - 右对齐选择元素 (CSS)
我有一个表单布局,我想显示左对齐的标签和右对齐的表单控件。我一直在尝试使用表单控件上的 float:right 使其工作(在本例中为 a ),然后对其应用clearfix 类,但clearfix 似乎不适用于我的选择框。
这里有什么问题吗?或者clearfix 预计不适用于选择元素?
然而,当我这样做时,选择框仍然延伸到包含 div 的底部之外。
我的代码:
<style type="text/css">
#category-select {
left: 0px;
top: 0px;
width: 350px;
border: 1px solid #666;
}
select#category {
float: right;
}
select.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
</style><!-- main stylesheet ends, CC with new stylesheet below... -->
<!--[if IE]>
<style type="text/css">
select.clearfix {
zoom: 1;
}
</style>
<![endif]-->
<div id="triage">
<div id="category-select">
Category:
<select class="ipad-dropdown clearfix" id="category" name="category">
<option value="A">A - Emergency
<option value="B">B - Urgent
<option value="C">C - ASAP
<option value="D" selected>D - Standard
</select>
</div>
</div>
I have a form layout that I want to display the label aligned left and the form control aligned right. I have been trying to get it to work using a float:right on the form control (in this case a ) and then applying the clearfix class to it but the clearfix does not appear to be working on my select box.
Is there something wrong here or is clearfix not expected to work on a select element?
When I do this however, the select box still extends outside the bottom of the containing div.
My Code:
<style type="text/css">
#category-select {
left: 0px;
top: 0px;
width: 350px;
border: 1px solid #666;
}
select#category {
float: right;
}
select.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
</style><!-- main stylesheet ends, CC with new stylesheet below... -->
<!--[if IE]>
<style type="text/css">
select.clearfix {
zoom: 1;
}
</style>
<![endif]-->
<div id="triage">
<div id="category-select">
Category:
<select class="ipad-dropdown clearfix" id="category" name="category">
<option value="A">A - Emergency
<option value="B">B - Urgent
<option value="C">C - ASAP
<option value="D" selected>D - Standard
</select>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果
select
元素是最高的元素,为什么不让标签浮动呢?您还可以借此机会将其设置为真正的标签,而不仅仅是div
中的一些文本。这是 CSS:这是 HTML:
这是演示。
If the
select
element is the tallest thing, why not float the label? You can also take the opportunity to make it actually a label instead of just some text in adiv
. Here's the CSS:Here's the HTML:
Here's the demo.
由于您浮动了选择元素,因此它不会再影响包含的 div 的高度。尝试向包含元素添加一些填充: http://jsfiddle.net/LZVhN/1/ (还为选择添加了一些相对定位)
Since you're floating the select element, it won't affect the height of the containing div anymore. Try adding some padding to the containing element: http://jsfiddle.net/LZVhN/1/ (also added some relative positioning to the select)