我正在创建一个横向分为三个部分的示例网站。我希望最左边的 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 出现在彼此之上。我要他们出现在彼此的身边!
我怎样才能做到这一点?
原文由 Akhil 发布,翻译遵循 CC BY-SA 4.0 许可协议
我不会在这种事情上使用花车;我宁愿使用
inline-block
。还有一些要考虑的要点:
<head>
和<body>
doctype
这是格式化文档的更好方法:
这是一个很好的衡量标准的 jsFiddle 。