CSS
#wrapper .tn{
width:auto;
height:20px;
line-height:20px;
float:left;
padding:5px 2px 5px 5px;
margin:0 5px 10px;
font-weight:bold;
background:#f0f0f0;
}HTML
<div id="wrapper">
<div class="tn">Text</div>
<div class="tn">Text</div>
<div class="tn">Text</div>
</div>上面的代码在FF,Chrome,Safari,Opera,IE9,IE8中运行流畅。但对于IE7来说,这是个问题。Div不会根据text.It cover wrapper div的宽度展开。我该如何解决这个问题呢?
发布于 2012-12-24 23:37:10
在我看来很好,使用IE7开发人员工具检查,您可以尝试display: inline-block;而不是float
#wrapper .tn{
height:20px;
line-height:20px;
padding:5px 2px 5px 5px;
margin:0 5px 10px;
font-weight:bold;
background:#f0f0f0;
display: inline-block;
}发布于 2012-12-24 23:57:03
我假设您所说的div是#wrapper?#wrapper不会扩展,因为您需要清除浮动
查看HTML5样板文件(https://github.com/h5bp/html5-boilerplate/blob/master/css/main.css)中的clearfix类
.clearfix:before,
.clearfix:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.clearfix:after {
clear: both;
}
/*
* For IE 6/7 only
* Include this rule to trigger hasLayout and contain floats.
*/
.clearfix {
*zoom: 1;
}所以在你的代码中这样做:
<div id="wrapper" class="clearfix">
<div class="tn">Text</div>
<div class="tn">Text</div>
<div class="tn">Text</div>
</div>https://stackoverflow.com/questions/14023155
复制相似问题