網站通常會顯示多個列的內容(like a magazine or newspaper) 。
城市規劃展覽館
倫敦
巴黎
東京
巴黎
東京
倫敦
倫敦是英國的首都城市。 它是英國人口最多的城市,有超過13萬居民的大都市區。
站在泰晤士河,倫敦一直是主要解決兩千年來,它的歷史可以追溯到羅馬人,誰把它命名為倫迪尼烏姆成立。
版權所有©w3ii.com
HTML佈局使用<div>元素
所述<div>元件經常被用來作為佈局的工具,因為它可以很容易地定位成與CSS。
此示例使用四個<div>元素來創建多列佈局:
例
<body>
<div id="header">
<h1>City Gallery</h1>
</div>
<div id="nav">
London<br>
Paris<br>
Tokyo
</div>
<div id="section">
<h1>London</h1>
<p>London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.</p>
<p>Standing on the River Thames, London has been a major settlement for two millennia,
its history going back to its founding by the Romans, who named it Londinium.</p>
</div>
<div id="footer">
Copyright © w3ii.com
</div>
</body>
試一試» CSS的:
<style>
#header {
background-color:black;
color:white;
text-align:center;
padding:5px;
}
#nav {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
float:left;
padding:5px;
}
#section {
width:350px;
float:left;
padding:10px;
}
#footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
</style>
網站佈局使用HTML5
HTML5提供了定義網頁的不同部分新的語義元素:
|
此示例使用<header> , <nav> <section> ,和<footer>創建多列佈局:
例
<body>
<header>
<h1>City Gallery</h1>
</header>
<nav>
London<br>
Paris<br>
Tokyo
</nav>
<section>
<h1>London</h1>
<p>London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.</p>
<p>Standing on the River Thames, London has been a major settlement for two millennia,
its history going back to its founding by the Romans, who named it Londinium.</p>
</section>
<footer>
Copyright © w3ii.com
</footer>
</body>
試一試» CSS的:
<style>
header {
background-color:black;
color:white;
text-align:center;
padding:5px;
}
nav {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
float:left;
padding:5px;
}
section {
width:350px;
float:left;
padding:10px;
}
footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
</style>
HTML佈局使用表
所述<table>元素沒有被設計成為一個佈局工具。
所述的目的<table>元素是顯示表格數據。
佈局可以使用取得的<table>元素,因為表元素可以與CSS設置樣式:
例
<body>
<table class="lamp">
<tr>
<th>
<img src="../images/lamp.jpg" alt="Note" style="height:32px;width:32px">
</th>
<td>
The table element was not designed to be a layout tool.
</td>
</tr>
</table>
</body>
試一試» CSS的:
<style>
table.lamp {
width:100%;
border:1px solid #d4d4d4;
}
table.lamp th, td {
padding:10px;
}
table.lamp th {
width:40px;
}
</style>
警告:表的創建佈局並沒有錯,但不建議吧! 避免創建佈局表格。