P粉4784456712023-08-22 13:51:31
I know this is a very old question. I'm posting a solution to this problem here, using FlexBox. Here is the solution:
#container { height: 100%; width: 100%; display: flex; } #leftThing { width: 25%; background-color: blue; } #content { width: 50%; background-color: green; } #rightThing { width: 25%; background-color: yellow; }
<div id="container"> <div id="leftThing"> 左侧菜单 </div> <div id="content"> 随机内容 </div> <div id="rightThing"> 右侧菜单 </div> </div>
Just add display:flex
to the container! No need to use floats.
P粉8422150062023-08-22 11:58:42
I recommend not using floats to handle this situation, I prefer to use inline-block
.
A few more points to consider:
<head>
and <body>
doctype
Here is a better way to format the document:
<!DOCTYPE html> <html> <head> <title>网站标题</title> <style type="text/css"> * {margin: 0; padding: 0;} #container {height: 100%; width:100%; font-size: 0;} #left, #middle, #right {display: inline-block; *display: inline; zoom: 1; vertical-align: top; font-size: 12px;} #left {width: 25%; background: blue;} #middle {width: 50%; background: green;} #right {width: 25%; background: yellow;} </style> </head> <body> <div id="container"> <div id="left">左侧菜单</div> <div id="middle">随机内容</div> <div id="right">右侧菜单</div> </div> </body> </html>
There is also a jsFiddle for reference.