国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > CSS > 正文

CSS 利用table實現五種常用布局的方法示例

2024-07-11 08:58:50
字體:
來源:轉載
供稿:網友

本文介紹了CSS 利用table實現五種常用布局的方法示例,分享給大家,具體如下:

布局一:

效果:

代碼:

html:

<div class="header">header</div><div class="main">main</div><div class="footer">footer</div>

注意:div中要有內容,不然顯示不出來

css:

body{  margin:0;  padding:0;  width:100%;  min-height:100vh;  display:table;  text-align:center;}.header,.main,.footer{  display:table-row;}.header{  height:50px;  background:tomato;}.main{  background:skyblue;}.footer{  height:50px;  background:#9d70ff;}

布局二:

效果:

代碼:

html:

<div class="header">header</div><div class="main">  <div class="left">left</div>  <div class="right">right</div></div><div class="footer">footer</div>

css:

body{  margin:0;  padding:0;  width:100%;  min-height:100vh;  display:table;  text-align:center;}.header,.main,.footer{  display:table-row;}.header{  height:50px;  background:tomato;}.main{  width:100%;  display:table;  height:calc(100vh - 100px);}.main .left{  width:300px;  display:table-cell;  background:#fcea96;}.main .right{  display:table-cell;  background:skyblue;}.footer{  height:50px;  background:#9d70ff;}

注意:.main的height屬性中的100px是header和footer的高度之和

布局三:

效果:

代碼:

html:

<div class="left">left</div><div class="right">  <div class="header">header</div>  <div class="main">main</div>  <div class="footer">footer</div></div>

css:

body{  margin:0;  padding:0;  min-height:100vh;  display:table;  text-align:center;}.left{  display:table-cell;  width:200px;  background:tomato;}.right{  display:table;  width:calc(100vw - 200px);  height:100vh;}.header,.main,.footer{  display:table-row;}.header{  height:50px;  background:skyblue;}.main{  background:#fcea96;}.footer{  height:50px;  background:#9d70ff;}

布局四(雙欄布局,例子為左邊固定,右邊自適應):

效果:

代碼:

html:

<div class="left">left</div><div class="right">right</div>

css:

body{  margin:0;  padding:0;  width:100%;  height:100vh;  display:table;  text-align:center;}.left,.right{  display:table-cell;}.left{  width:300px;  background:tomato;}.right{  background:skyblue;}

布局五(三欄布局,例子為左邊固定,右邊固定,中間自適應):

效果:

代碼:

html:

<div class="left">left</div><div class="middle">middle</div><div class="right">right</div>

css:

body{  margin:0;  padding:0;  width:100%;  height:100vh;  display:table;  text-align:center;}.left,.middle,.right{  display:table-cell;}.left{  width:300px;  background:tomato;}.middle{  background:#ffe69e;}.right{  width:200px;  background:skyblue;}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 浦县| 公安县| 两当县| 武乡县| 电白县| 阿拉尔市| 西乌珠穆沁旗| 赤水市| 安平县| 彭泽县| 永仁县| 裕民县| 巴马| 伊川县| 灵石县| 晋城| 威远县| 库伦旗| 斗六市| 碌曲县| 莱芜市| 库伦旗| 潢川县| 萨嘎县| 吉首市| 柯坪县| 定襄县| 会理县| 北碚区| 伊宁市| 曲麻莱县| 山阳县| 西吉县| 兴安县| 潜江市| 乌审旗| 枣庄市| 安福县| 浦江县| 河曲县| 马边|