如何让正确的div位于顶部而不是底部?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
body
{
padding: 0;
margin: 0;
}
#all
{
width: 955px;
margin: 0 auto;
background: #F4FEC0;
}
#dleft
{
margin-right: 200px;
}
#dright
{
float: right;
width: 200px;
margin-left: 755px;
}
</style>
</head>
<body>
<div id="all">
<div id="dleft">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec et odio elit. Praesent ut sem nibh, non ultricies purus. Integer viverra dapibus nulla. Nulla quis quam mauris, et faucibus arcu. Integer quis est a libero lacinia tincidunt. Duis dignissim dui nec quam vehicula nec eleifend dolor scelerisque. Cras vehicula, mauris quis pretium gravida, justo tellus tincidunt nunc, faucibus euismod enim sapien at neque. Fusce quis elit ut elit commodo pulvinar id sit amet urna. Mauris sapien lacus, auctor eu posuere at, mattis in elit. Sed congue ultricies diam, sit amet placerat quam rutrum ac. Vivamus pellentesque tristique nisi, a consectetur sem dignissim in. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc rhoncus dolor nibh. In ornare mattis lectus, id mattis felis iaculis vel. Maecenas quis tellus eu est luctus mattis eu id urna. Vestibulum eu elit eget magna malesuada adipiscing. Vestibulum sem neque, condimentum eget luctus vel, rhoncus vel tellus. Donec egestas quam id erat dignissim tempus. Cras volutpat erat ac enim fermentum eu convallis quam porttitor. Quisque ac tellus sit amet libero interdum sodales.
</div>
<div id="dright">
menu<br />
menu<br />
menu<br />
menu<br />
</div>
</div>
</body>
</html>
答案 0 :(得分:3)
#dleft
{
float:left;
width:755px;
}
#dright
{
float: left;
width: 200px;
}
答案 1 :(得分:1)
#dright
{
position:absolute;
left:775px;
top:0;
width: 200px;
}
答案 2 :(得分:0)
您的dleft
div没有设置width
,因此会尝试填充整个容器。为width
设置dleft
,看到容器的宽度是955px,那么这应该不超过755px,或者position:absolute; top:0;
的CSS中有dright
。
答案 3 :(得分:0)
如果您不介意移动某些HTML,这是一个简单的解决方案:
从#dright
,删除margin-left
属性。
在HTML中,将<div id="dright">
移至<div id="dleft">
之前。
要#all
,请添加overflow: auto
- 如果您的权利<div>
高于您的左侧,则clear the float需要这样做。