11 Star 37 Fork 20

Baryy / You-need-to-know-css

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
double-wing-layout.md 3.05 KB
一键复制 编辑 原始数据 按行查看 历史
LHammer 提交于 2018-04-18 11:46 . :bug:amend comments~

双飞翼布局

此布局的需求同圣杯布局一样,都为两边等宽,中间自适应的三栏布局,源自淘宝UED

<script v-pre type="text/x-template" id="double-wing-layout"> <style> main { width: 100%; padding: 39px 29px; font-size: 12px; } section { box-shadow: 0 0 0 1px #eee; } section::after { content: ''; display: block; clear: both; } section > div { height: 229px; line-height: 1.5em; text-align: center; float: left; color: white; } section .left, section .right { width: 119px; padding-top: 29px; background: #b4a078; } section .left { margin-left: -100%; } section .center { width: 100%; text-align: justify; hyphens: auto; } section .center-inner { height: 100%; margin: 0 129px; padding: 29px 12px; background: #b4a078; } section .right { margin-left: -119px; } /* input range */ input[type="range"] { width: 100%; cursor: ew-resize; } </style>
A paragraph of filler text. La la la de dah de dah de dah de la.
left
right
<script> module.exports = { data () { return { width: 100 } }, mounted() { const self = this; this.$refs.range.oninput = function () { self.width = 60 + this.value * .4; } } } </script> </script>

圣杯布局和双飞翼布局的区别

圣杯布局和双飞翼布局解决问题的方案在前一半是相同的,也就是三栏全部float浮动,但左右两栏加上负margin让其跟中间栏div并排,以形成三栏布局。

不同在于解决”中间栏div内容不被遮挡“问题的思路不一样:圣杯布局,为了中间div内容不被遮挡,将中间div设置了左右padding-left和padding-right后,将左右两个div用相对布局position: relative并分别配合right和left属性,以便左右两栏div移动后不遮挡中间div。

双飞翼布局,为了中间div内容不被遮挡,直接在中间div内部创建子div用于放置内容,在该子div里用margin-left和margin-right为左右两栏div留出位置。多了1个div,少用大致4个css属性(圣杯布局中间divpadding-left和padding-right这2个属性,加上左右两个div用相对布局position: relative及对应的right和left共4个属性,一共6个;而双飞翼布局子div里用margin-left和margin-right共2个属性,6-2=4),个人感觉比圣杯布局思路更直接和简洁一点。

?> 作者:吕延庆
链接:https://www.zhihu.com/question/21504052/answer/50053054
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

CSS
1
https://gitee.com/lhammer/You-need-to-know-css.git
git@gitee.com:lhammer/You-need-to-know-css.git
lhammer
You-need-to-know-css
You-need-to-know-css
master

搜索帮助