Mit*_*ran 3 css clear css-float internet-explorer-7
我有一个field_wrapper类div,它包含3个子divs field_label,field_input和field_error
我需要将field_label,field_input并排放在前两个下面的field_error中.
请看下面的css代码,知道我是如何实现这一点的,我的问题是它在IE7中不起作用.清除两者应用于field_error不起作用.
即使经过谷歌搜索很长一段时间,我也找不到合适的方法来解决这个问题而不添加HTML标记.请提示css技巧或任何其他方法以避免额外的标记代码
.field_wrapper
{
clear:both;
}
.field_label
{
float:left;
width:40%;
}
.field_input
{
float:left;
width:40%;
}
.field_error
{
clear: both;
color:#FF0000;
float: right;
text-align:left;
width: 60%;
}
<form method="post" action="http://localhost/locations/add">
<div class="field_wrapper">
<div class="field_label">
<label for="location_add_name">Name</label>
</div>
<div class="field_input">
<input type="text" id="location_add_name" value="" name="name">
</div>
<div class="field_error">
<p>The Name field is required.</p>
</div>
</div>
<div class="field_wrapper">
<div class="field_label">
Address
</div>
<div class="field_input">
<textarea id="location_add_address" rows="12" cols="90" name="address"></textarea>
</div>
<div class="field_error">
</div>
</div>
<div class="form_submit">
<input type="submit" value="Add" name="submit">
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
如果你不想删除左边的浮动.您可以使用此包装器代码
.field_wrapper { display: inline-block; }
.field_wrapper:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
* html .field_wrapper { height: 1%; }
.field_wrapper{ display: block; }
Run Code Online (Sandbox Code Playgroud)
它每次都适合我(IE6也是如此)
更新:
我再次看了一遍,并稍微更改了标记,也使它有效xhtml.只需将课程放在P标签上,您就不需要额外的div.
.field_wrapper
{
clear:both;
}
.field_label
{
float:left;
width:40%;
}
.field_input
{
float:left;
width:40%;
}
.field_error
{
clear: both;
color:#f00;
width: 60%;
}
<form method="post" action="http://localhost/locations/add">
<div class="field_wrapper">
<div class="field_label">
<label for="location_add_name">Name</label>
</div>
<div class="field_input">
<input type="text" id="location_add_name" value="" name="name" />
<p class="field_error">The Name field is required.</p>
</div>
</div>
<div class="field_wrapper">
<div class="field_label">Address</div>
<div class="field_input">
<textarea id="location_add_address" rows="12" cols="90" name="address"></textarea>
</div>
</div>
<div class="form_submit">
<input type="submit" value="Add" name="submit" />
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20753 次 |
| 最近记录: |