溫馨提示×

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

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

html中如何實(shí)現(xiàn)兩欄布局

發(fā)布時(shí)間:2021-12-03 11:09:57 來(lái)源:億速云 閱讀:527 作者:小新 欄目:web開(kāi)發(fā)

這篇文章給大家分享的是有關(guān)html中如何實(shí)現(xiàn)兩欄布局的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。

html中實(shí)現(xiàn)兩欄布局的方法:1、利用float屬性和margin屬性來(lái)實(shí)現(xiàn);2、利用BFC技術(shù)來(lái)實(shí)現(xiàn);3、利用table布局技術(shù)來(lái)實(shí)現(xiàn);4、利用flex彈性布局技術(shù)來(lái)實(shí)現(xiàn);5、利用grid網(wǎng)格布局技術(shù)來(lái)實(shí)現(xiàn)。

本教程操作環(huán)境:windows7系統(tǒng)、CSS3&&HTML5版、Dell G3電腦。

html網(wǎng)頁(yè)中實(shí)現(xiàn)兩欄布局

1、利用float+margin實(shí)現(xiàn)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.left1 {
height: 300px;
background-color: red;
width: 400px;
float: left;
}

.right1 {
width: 400px;
height: 300px;
background-color: green;
margin-left: 400px;
}
</style>
</head>
<body>
<div></div>
<div></div>
</body>
</html>

2、利用BFC實(shí)現(xiàn)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.left2 {
height: 300px;
background-color: red;
width: 400px;
float: left;
}

.right2 {
height: 300px;
background-color: blue;
overflow: hidden;
}
</style>
</head>
<body>
<div></div>
<div></div>
</body>
</html>

3、利用table布局

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.parent {
display: table;
width: 100%;
table-layout: fixed;
}

.left3 {
display: table-cell;
height: 300px;
width: 300px;
background-color: pink;
}

.right3 {
display: table-cell;
height: 300px;
background-color: purple;
}
</style>
</head>
<body>
<div>
<div></div>
<div></div>
</div>
</body>
</html>

4、利用flex布局

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.parentf {
display: flex;
flex-direction: row;
justify-content: flex-start;
width: 100%;
}

.left4 {
height: 300px;
width: 300px;
background-color: skyblue;
}

.right4 {
height: 300px;
width: 100%;
background-color: yellowgreen;
}
</style>
</head>
<body>
<div>
<div></div>
<div></div>
</div>
</body>
</html>

5、利用grid布局

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.parent {
height: 400px;
display: grid;
grid-template-columns: 50% 50%;
width: 100%;
}

.left5 {
background-color: skyblue;
}

.right5 {
background-color: pink;
}
</style>
</head>
<body>
<div>
<div></div>
<div></div>
</div>
</body>
</html>

感謝各位的閱讀!關(guān)于“html中如何實(shí)現(xiàn)兩欄布局”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

向AI問(wèn)一下細(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