【发布时间】:2019-11-14 21:33:05
【问题描述】:
我一直在尝试使用 CSS 实现两列布局,其中左列用于导航(不要对我持有垂直导航),右列用于内容。内容的长度各不相同,但总是比右栏导航长。我的目标是至少在
我看到有 other questions 的目标有点相似,这就是我找到 this article 的方式。
在尝试将它应用到我的设计之后,我想出了一些我认为可行的方法。
jsfiddle 在这里:http://jsfiddle.net/FVsSV/2/
相关 HTML:
<div id="mainCont">
<div id="sidebar">
<a href="#">dapibus sit a</a>
<a href="#">dapibus sit a</a>
<a href="#">dapibus sit ag</a>
<a href="#">dapibus sit a</a>
<a href="#">dapibus sit a</a>
<a href="#">dapibus sit a</a>
<a href="#">dapibus sit a</a>
</div>
<div id="content">
<div id="padding-wrapper">
<h1>uris et lorem gravida condiment</h1>
<h3 id="toc">apibus sit am</h3>
Content content content...
</div>
</div>
</div>
相关CSS:
#mainCont {
background-color: #000;
overflow: hidden;
padding-left: 148px; /* The width of the rail */
height:1%; /* So IE plays nice */
}
#sidebar {
display: inline;
background-color: #9BBCE4;
width: 148px;
float: left;
margin-left: -148px;
}
#sidebar a {
display: block;
padding: 15px 0px;
font-size: 1.1em;
text-align: center;
color: #2C2C2C;
text-decoration: none
}
#sidebar a:hover {
background-color: #4e88ce;
color: #FFFFFF;
}
#content{
background-color: #FFFFFF;
width:100%;
border-left: 148px solid #9BBCE4;
margin-left:-148px;
}
#padding-wrapper {
padding: 30px 30px;
}
/* content formatting*/
#content h1 {
font-size: 1.5em;
margin: 15px 0px 20px 0px;
}
/* content formatting END*/
它在 FF8 和 IE8 中看起来还不错,但是当我在 IE 7 和“兼容性视图”中检查它时,它看起来很乱,我不确定原因是什么,或者是否可以轻松修复。
我是否缺少明显的东西,或者这种方法不值得为 IE6-7 兼容性尝试?
【问题讨论】:
-
不要将“inline”和“float”结合起来。只需使用“浮动”
-
@Diodeus:
display: inline样式是IE6's double margin bug on floated elements 的解决方法。其他浏览器会安全地忽略该声明并将元素转换为块。
标签: css internet-explorer cross-browser