溫馨提示×

溫馨提示×

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

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

怎么在CSS中利用table布局示例

發(fā)布時間:2021-04-08 16:56:57 來源:億速云 閱讀:188 作者:Leah 欄目:web開發(fā)

怎么在CSS中利用table布局示例?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。

布局一:

效果:

怎么在CSS中利用table布局示例

代碼:

html:

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

注意:div中要有內(nèi)容,不然顯示不出來

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;
}

布局二:

效果:

怎么在CSS中利用table布局示例

代碼:

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的高度之和

布局三:

效果:

怎么在CSS中利用table布局示例

代碼:

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;
}

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

效果:

怎么在CSS中利用table布局示例

代碼:

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;
}

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

效果:

怎么在CSS中利用table布局示例

代碼:

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;
}

看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進一步的了解或閱讀更多相關(guān)文章,請關(guān)注億速云行業(yè)資訊頻道,感謝您對億速云的支持。

向AI問一下細節(jié)

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

AI