【发布时间】:2009-08-18 03:44:33
【问题描述】:
我有一个列表,我希望主要元素垂直对齐,每个元素的子元素下拉到主要元素下方。我想在 subNav 类上保留 position: absolute ,因为这个导航的宽度会有所不同,所以我不能设置宽度。这在 Firefox 中有效,但在 IE 7 中,绝对会导致子导航显示内联(因此从我想要的位置向右和向上移动)。我该如何解决这个问题?
例子:
<style>
#nav ul, #nav li ul {
list-style-type: none;
margin: 0;
padding: 0;
}
#nav li {
float: left;
width: 120px;
border-right: 1px solid #000;
padding: 10px;
}
#nav li ul li {
float: none;
width: auto;
height: auto;
border-right: none;
text-align: left;
padding: 0;
}
#nav .subNav {
background: #eee;
position: absolute;
padding: 10px;
}
</style>
</head>
<body>
<div id="nav">
<ul>
<li>Main One
<ul class="subNav">
<li>Sub One A</li>
<li>Sub One B</li>
</ul>
</li>
<li>Main Two
<ul class="subNav">
<li>Sub Two A</li>
<li>Sub Two B</li>
</ul>
</li>
</ul>
</div>
</body>
【问题讨论】:
标签: html css internet-explorer