溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

HTML如何使用div元素實(shí)現(xiàn)布局

發(fā)布時(shí)間:2022-02-24 11:18:01 來源:億速云 閱讀:355 作者:小新 欄目:web開發(fā)

這篇文章將為大家詳細(xì)講解有關(guān)HTML如何使用div元素實(shí)現(xiàn)布局,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

使用 <div> 元素的 HTML 布局

注釋:<div> 元素常用作布局工具,因?yàn)槟軌蜉p松地通過 CSS 對(duì)其進(jìn)行定位。

這個(gè)例子使用了四個(gè) <div> 元素來創(chuàng)建多列布局:

<html>
<head>
<style>
#header {
 background-color:#1aaa11;
 color:white;
 text-align:center;
 padding:5px;
}
#nav {
 line-height:30px;
 background-color:#eeeeee;
 color:#faaaff;
 height:300px;
 width:100px;
 float:left;
 padding:5px;	 
}
#section {
 width:350px;
 float:left;
 padding:10px;	 	 
}
#footer {
 background-color:#166611;
 color:white;
 clear:both;
 text-align:center;
 padding:5px;	 	 
}
</style>
</head>
<body>
<div id="header">
<h2>天華信息教育</h2>
</div>
<div id="nav" >
第一組<br>
第二組<br>
第三組<br>
</div>
<div id="section">
<h3>這是標(biāo)題</h3>
<p>
這是內(nèi)容
</p>
<p>
這是內(nèi)容
</p>
</div>
<div id="footer">
天華信息教育
</div>
</body>
</html>

HTML如何使用div元素實(shí)現(xiàn)布局

HTML基礎(chǔ)教程:div元素實(shí)現(xiàn)布局

HTML5 語義元素

header 定義文檔或節(jié)的頁眉

nav 定義導(dǎo)航鏈接的容器

section 定義文檔中的節(jié)

article 定義獨(dú)立的自包含文章

aside 定義內(nèi)容之外的內(nèi)容(比如側(cè)欄)

footer 定義文檔或節(jié)的頁腳

details 定義額外的細(xì)節(jié)

summary 定義 details 元素的標(biāo)題

<html>
<head>
<style>
header {
 background-color:#1aaa11;
 color:white;
 text-align:center;
 padding:5px;	 
}
nav {
 line-height:30px;
 background-color:#eeeeee;
 color:#faaaff;
 height:300px;
 width:100px;
 float:left;
 padding:5px;	 
}
section {
 width:350px;
 float:left;
 padding:10px;	 	 
}
footer {
 background-color:#166611;
 color:white;
 clear:both;
 text-align:center;
 padding:5px;	 	 
}
</style>
</head>
<body>
<header>
<h2>天華信息教育</h2>
</header>
<nav>
第一組<br/>
第二組<br/>
第三組<br/>
</nav>
<section>
<h2>這是標(biāo)題</h2>
<p>
這是內(nèi)容
</p>
<p>
這是內(nèi)容
</p>
</section>
<footer>
天華信息教育
</footer>
</body>
</html>

HTML如何使用div元素實(shí)現(xiàn)布局

關(guān)于“HTML如何使用div元素實(shí)現(xiàn)布局”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI