#container
{
height:100%;
width:100%;
border:5px solid red;
margin:0px;
}
#hbox1
{
position:absolute
left:5px;
top:5px;
height:130px;
width:150px;
border:5px solid red;
margin:5px;
}
#hbox2
{
position:absolute
left:150px;
top:5px;
height:130px;
width:150px;
border:5px solid red;
margin:5px;
}
我需要在 hbox1 的旁边添加 hbox2,但它显示在 hbox1 的底部...我尝试使用绝对定位来定位 hbox2...但它不起作用...
最佳答案
我也建议使用内联 block 。但不要忘记在容器 div 上设置 font-size:0 以去除任何奇怪的空格。
此外,由于您将使用内联 block ,因此您不再需要设置 TOP 和 LEFT 来使 hbox1 和 hbox2 相同,在这种情况下您应该使用单个类而不是两个 id
看看吧!我建议尝试使用以下链接中的值(进行更改时点击运行以查看差异)以了解有关所有功能的更多信息。
#container{
height:100%;
width:100%;
border:5px solid red;
margin:0px;
font-size:0px;
}
.hbox{
display:inline-block;
height:130px;
width:150px;
border:5px solid red;
margin:5px;
}
<div id="container">
<div class="hbox"></div>
<div class="hbox"></div>
</div>
关于css - 将css中的元素定位在页面上指定的像素处,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22713409/