本文介绍了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; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
打开软件,我们按快捷键ctrl+n,建立一个新的文件。 点击常用,选择布局。 点击...
作者 / Krish Vitaldevara,Google Play 信任与安全产品管理总监 多年来,向数十...
在讲CSS优先级之前,我们得要了解什么是CSS,CSS是用来做什么的。 首先,我们对C...
背景 京东购物小程序作为京东小程序业务流量的主要入口,承载着许多的活动和页面...
Dreamweaver中如何使用Flash影片 1、首先需要我们准备的是一个Flash文件,其次最...
行高line-height实现单行文本垂直居中 以前一直认为单行文本垂直居中要将高度和...
一、作用 离线浏览 - 根据文件规则把资源缓存在本地,脱机依然能够访问资源,联...
最近在做项目时,发现CSS3中关于动画的技术,自己很少运用在项目中,平时一些列...
在ie下设置 css 样式 style="cursor:hand;" 可以正常显示 但是在firefox下就不行...
CSS3实现酷炫的3D旋转透视 3D动画效果现在越来越普及,已经被广泛的应用到了各个...