本文主要和大家介绍了css布局实现左中右布局的5种方式的相关资料,小编觉得挺不错的,现在分享给大家,也给大家做个参考,希望能帮助到大家。
效果如下:

左中右布局
Document html *{ margin: 0; padding: 0; } article{ height: 100px; } section{ margin-top: 10px; } .left{ width: 300px; height: 100px; background-color: #823384; text-align: center; font-size: 20px; color: #fdf6e3; } .center{ height: 100px; background-color: #d29922; } .right{ width: 300px; height: 100px; background-color: #0c8ac5; text-align: center; font-size: 20px; color: #fdf6e3; }.float article p{ } .float article .left{ float: left; } .float article .right{ float: right; } .float article .center{ } 左边
右边
浮动float布局:
左元素: float: left; 右元素: float: right; 中间元素:自动填充article{ position: relative; } .absolute .left-center-right p{ position: absolute; } .absolute .left-center-right .left{ left: 0; } .absolute .left-center-right .center{ left: 300px; right: 300px; } .absolute .left-center-right .right{ right: 0; } 左边
绝对absolute定位布局:
左边元素: position: absolute; left: 0; 右边元素: position: absolute; right:0; 中间元素: position: absolute;left:300px; right: 300px;右边
.flexbox .left-center-right{ display: flex; } .flexbox .left-center-right .left{ } .flexbox .left-center-right .center{ flex:1; } .flexbox .left-center-right .right{ } 左边
flex布局:
父元素display:flex; 左右子元素设置宽度300px; 中间子元素设置flex:1;右边
.table-box .left-center-right{ width: 100%; display: table; } .table-box .left-center-right>p{ display: table-cell; } .table-box .left-center-right .left{ } .table-box .left-center-right .center{ } .table-box .left-center-right .right { } 左边
表格table布局:
父元素width: 100%; display: table; 左右子元素display: table-cell; width: 300px;右边
.grid article{ display: grid; width: 100%; grid-template-rows: 100px; grid-template-columns: 300px auto 300px; } 左边
网格grid布局:
父元素宽度为100%, 父元素width: 100%; display:grid; grid-template-rows: 100; grid-template-columns: 300px auto 300px右边
相关推荐:
CSS布局之盒子模型属性
div和css布局的基本知识分享
六种css三栏布局方法示例
立即学习“前端免费学习笔记(深入)”;
以上就是5种css实现左中右布局的方式的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1609002.html
微信扫一扫
支付宝扫一扫