這篇文章主要介紹“CSS的單列布局怎么實現”,在日常操作中,相信很多人在CSS的單列布局怎么實現問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”CSS的單列布局怎么實現”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
單列布局中還能劃分為兩種,一種是等寬的單列布局;另一種是 header 和 footer 等寬并占滿屏幕,而 contant 略窄的單列布局。
在等寬單列布局中,我們需要對 header、contant、footer 都設置同樣的寬度,設置寬度可以使用 width 或者 max-width 兩個屬性,兩者不同的區別的在于,當屏幕小于設置的寬度時,width 會出現滾動條,而 max-width 顯示屏幕實際的寬度。設完寬度后,在設置 margin:0 auto; 實現居中。
實現代碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSS實現單列布局 - 億速云(yisu.com)</title>
<style type="text/css">
.header{
max-width: 1080px;
height: 100px;
margin: 0 auto;
background-color: gray;
}
.contant{
max-width: 1080px;
height: 500px;
margin: 0 auto;
background-color: red;
}
.footer{
max-width: 1080px;
height: 100px;
margin: 0 auto;
background-color: gray;
}
</style>
</head>
<body>
<div class="header"></div>
<div class="contant"></div>
<div class="footer"></div>
</body>
</html>不等寬的實現原理與上述相似,只是不在設置header與footer設置寬度,而在contant中設置寬度即可。
源代碼如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSS實現單列布局 - 億速云(yisu.com)</title>
<style type="text/css">
.header{
height: 100px;
margin: 0 auto;
background-color: gray;
}
.contant{
max-width: 1080px;
height: 500px;
margin: 0 auto;
background-color: red;
}
.footer{
height: 100px;
margin: 0 auto;
background-color: gray;
}
</style>
</head>
<body>
<div class="header"></div>
<div class="contant"></div>
<div class="footer"></div>
</body>
</html>到此,關于“CSS的單列布局怎么實現”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。