1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > css中圣杯布局和双飞翼布局的介绍(code)

css中圣杯布局和双飞翼布局的介绍(code)

时间:2018-09-17 15:40:25

相关推荐

css中圣杯布局和双飞翼布局的介绍(code)

web前端|css教程

双飞翼布局,圣杯布局,布局,css

web前端-css教程

这篇文章给大家介绍的内容是关于css中圣杯布局和双飞翼布局的介绍(附代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

冒险岛062源码,vscode游戏主题,服务器能用ubuntu桌面版吗,tomcat性能情况,sqlite3 推出,织梦报名插件utf 8,阿里可视化前端框架,python3爬虫示例,php 域名 正则,kdp频道seo,php网站投票源码,网页设计模板html,女的干模板机好嘛lzw

圣杯布局

照片相册存储分享源码 下载,ubuntu安装教程管道,tomcat日志文件不存在,爬虫用户平台,php打印乘法九九表,seo软文讲解lzw

#header

#center

#left

#right

#footer

实现的效果主要在container中,left 和 rgith固定宽度,center首先渲染,且自适应宽度。

贷款中介利用源码,vscode如何统计代码规模,ubuntu升级 软件,tomcat允许中括号,梦见踩死爬虫,php表单写入数据库,仙桃seo关键词推广,网站免费模版代码,网页html静态模板lzw

body {min-width: 500px; } #container {overflow: auto; /* BFC */padding-left: 180px;padding-right: 150px; } #container .column {height: 200px;position: relative;float: left; } #center {background-color: #e9e9e9;width: 100%; } #left {background-color: red;width: 180px;right: 180px; margin-left: -100% } #right {background-color: blue;width: 150px; margin-right: -150px; } #header,#footer {background-color: #c9c9c9; }

该方案几个注意的点:

center元素位于left和right之前,可以让center先渲染,用户首先看到页面的主要内容。

container (width:100%)包裹着三栏内容,通过padding-left和padding-right为左右两栏腾出空间。

center,left,right都设置一个左浮动(float:left),所以container内部是一个浮动流。

通过给 left 元素设置margin-left: -100%,使得left移动到container的左上角,在通过position:relative; right: 180px,移动到container的padding-left的位置上去。

给right 元素设置margin-right: -150px,使得它移动到container的padding-right的位置上去。

圣杯布局(flexbox实现)

#header

#center

#left

#right

#footer

body {min-width: 550px;} #HolyGrail {display: flex;min-height: 100vh;flex-direction: column; } #container {display: flex;flex: 1; } #center {background-color: #e9e9e9;flex: 1; } #left {background-color: red;order: -1;width: 150px; } #right {background-color: blue;width: 150px; } #header,#footer {height: 50px;background-color: #c9c9c9; }

如果不考虑ie10及以下的浏览器,那么可以使用flex来实现圣杯布局。而且圣杯布局可以通过让container填充高度来使得footer达到一个sticky的效果。

flex兼容性

双飞翼布局

圣杯布局和双飞翼布局解决的问题是一样的,就是两边定宽,中间自适应的三栏布局,中间栏要在放在文档流前面以优先渲染。圣杯布局和双飞翼布局解决问题的方案在前一半是相同的,也就是三栏全部float浮动,但左右两栏加上负margin让其跟中间栏p并排,以形成三栏布局。不同的地方在于解决中间p内容不被遮挡的思路上面

圣杯布局的为了中间内容不被修改,是通过包裹元素的padding-leftpadding-right来使得内容p置于中间,然后再通过相对定位position:relative,配合right或left属性让左右两栏不则当中间内容。

双飞翼布局的解决方案是:通过再中间元素的内部新增一个p用于放置内容,然后通过左右外边距margin-leftmargin-right为左右两栏留出位置。

双飞翼布局多了1个p标签,少用了4个css属性。少用了padding-left,padding-right,左右两个p用相对布局position: relative及对应的right和left,多了margin-left,margin-right。

#header

#center

#left

#right

#footer

body {min-width: 500px;} #container {overflow: auto; /* BFC */ } #container .column {height: 200px;float: left; } #center {background-color: #e9e9e9;width: 100%; } #center-content {margin-left: 180px;margin-right: 150px; }#left {width: 180px;background-color: red;margin-left: -100%; } #right {background-color: blue;width: 150px; margin-left: -150px;} #header,#footer {background-color: #c9c9c9; }

相关文章推荐:

css中如何实现浮动的元素换行

CSS中Grid布局的用法总结(附代码)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。