【发布时间】:2013-05-09 06:33:04
【问题描述】:
根据w3schools.com了解到该元素是块级元素(即浏览器会在其前后显示一个换行符)。
那么 2 个 div 怎么能并排放置呢?
来自 w3schools 的一些代码:
<!DOCTYPE html>
<html>
<body>
<div id="container" style="width:500px">
<div id="header" style="background-color:#FFA500;">
<h1 style="margin-bottom:0;">Main Title of Web Page</h1>
</div>
<div id="menu" style="background color:#FFD700;height:200px;width:100px;float:left;">
<b>Menu</b><br>
HTML<br>
CSS<br>
JavaScript
</div>
<div id="content" style="background-color:#EEEEEE;height:200px;width:400px;float:left;">Content goes here
</div>
<div id="footer" style="background-color:#FFA500;clear:both;text-align:center;">Copyright © W3Schools.com
</div>
</div>
</body>
</html>
【问题讨论】:
-
请看本站:w3fools.com
-
看看css float
-
和绝对定位以及将显示类型更改为其他内容,例如 inline-block... 真的取决于您在布局中需要什么。
标签: html