【发布时间】:2012-08-09 11:54:53
【问题描述】:
我正在创建一个横向分为三个部分的示例网站。 我希望最左边的 div 宽度为 25%,中间的 div 宽度为 50%,右边的宽度为 25%,以便这些分区水平填充所有 100% 的空间。
<html>
<title>
Website Title
</title>
<div id="the whole thing" style="height:100%; width:100%" >
<div id="leftThing" style="position: relative; width:25%; background-color:blue;">
Left Side Menu
</div>
<div id="content" style="position: relative; width:50%; background-color:green;">
Random Content
</div>
<div id="rightThing" style="position: relative; width:25%; background-color:yellow;">
Right Side Menu
</div>
</div>
</html>
当我执行此代码时,这些 div 会相互重叠。我希望它们出现在彼此旁边!
我该怎么做?
【问题讨论】:
-
将左侧 div 设置为“float:left”,将右侧 div 设置为“float:right”。
-
让它们向左浮动,它们将彼此堆叠。但是,我不确定 %-width 是否仍然会被应用,你应该测试一下。
-
@user1594853 如果回答对您有帮助,请将其标记为已接受。
-
@Jezen Thomas 看了你8年的回答,我终于明白了:)