我需要一个包含两个右对齐列的布局。因此,我创建了三个div(两个列和一个包装器):
有没有一种方法可以得到一个右对齐的双列布局,同时不失去水平滚动条?
<div id="wrapper">
<div id="left">
First column
</div>
<div id="right">
Second column
</div>
</div>
我将左边的 div
设置为浮动向左,右边的 div
设置为浮动向右,并为这三个 div
设置了正确的宽度:
#wrapper{
width:30em;
}
#left{
float:left;
width:10em;
}
#right{
float:right;
width:20em;
}
这一切看起来都符合预期...
没有将div浮动,如下所示:http://img690.imageshack.us/img690/5844/rightrightalign.png
...但是当我将wrapper
div浮动到右侧时,无论是WebKit还是Firefox在需要显示水平滚动条时都不会显示:
没有右对齐,如下所示:http://img690.imageshack.us/img690/8559/withoutrightalign.png
如果我使用position: absolute; right:0
,情况也是同样的。
完整的HTML文档示例:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<style type="text/css" media="screen">
#wrapper{
width:30em;
float:right; /* The problem line */}
#left{
float:left;
width:10em;
background: green;}
#right{
float:right;
width:20em;
background: red;}
</style>
</head>
<body>
<div id="wrapper">
<div id="left">Left</div>
<div id="right">Right</div>
</div>
</body>
</html>
有没有一种方法可以得到一个右对齐的双列布局,同时不失去水平滚动条?
overflow:auto
添加到body中,但都没有用。我要删除我的答案,以便问题能够引起更多关注。真的很想知道为什么会这样。 - Pekka