HTML 布局 -和如何 使用<div>
div 元素是用于分组 HTML 元素的块级元素。
下面的例子使用五个 div 元素来创建多列布局:
实例
<!DOCTYPE html>
<html>
<body>
<div id="container" style="width:500px">
<div id="header" style="">
<h1 style="margin-bottom:0;">Main Title of Web Page</h1></div>
<div id="menu" style="height:200px;width:100px;float:left;">
<b>Menu</b><br>
HTML<br>
CSS<br>
JavaScript</div>
<div id="content" style="height:200px;width:400px;float:left;">
Content goes here</div>
<div id="footer" style="clear:both;text-align:center;">
Copyright © W3Schools.com</div>
</div>
</body>
</html>
<html>
<body>
<div id="container" style="width:500px">
<div id="header" style="">
<h1 style="margin-bottom:0;">Main Title of Web Page</h1></div>
<div id="menu" style="height:200px;width:100px;float:left;">
<b>Menu</b><br>
HTML<br>
CSS<br>
JavaScript</div>
<div id="content" style="height:200px;width:400px;float:left;">
Content goes here</div>
<div id="footer" style="clear:both;text-align:center;">
Copyright © W3Schools.com</div>
</div>
</body>
</html>
上面的 HTML 代码会产生如下结果如图

下面的例子使用三行两列的表格 - 第一和最后一行使用 colspan 属性来横跨两列:
实例
<!DOCTYPE html>
<html>
<body>
<table width="500" border="0">
<tr>
<td colspan="2" style="">
<h1>Main Title of Web Page</h1>
</td>
</tr>
<tr>
<td style="width:100px;">
<b>Menu</b><br>
HTML<br>
CSS<br>
JavaScript
</td>
<td style="height:200px;width:400px;">
Content goes here</td>
</tr>
<tr>
<td colspan="2" style="text-align:center;">
Copyright © W3Schools.com</td>
</tr>
</table>
</body>
</html>
<html>
<body>
<table width="500" border="0">
<tr>
<td colspan="2" style="">
<h1>Main Title of Web Page</h1>
</td>
</tr>
<tr>
<td style="width:100px;">
<b>Menu</b><br>
HTML<br>
CSS<br>
JavaScript
</td>
<td style="height:200px;width:400px;">
Content goes here</td>
</tr>
<tr>
<td colspan="2" style="text-align:center;">
Copyright © W3Schools.com</td>
</tr>
</table>
</body>
</html>
上面的代码显示的就是下面的图:

浙公网安备 33010602011771号