CSS 三栏布局

编程入门 行业动态 更新时间:2024-10-26 06:37:43

CSS 三栏<a href=https://www.elefans.com/category/jswz/34/1770549.html style=布局"/>

CSS 三栏布局

左右两列定宽,中间自适应

浮动+margin 

<style>.container {width: 500px;height: 200px;line-height: 200px;}.left {width: 100px;height: 100%;float: left;background: orange;text-align: center;}.right {width: 100px;height: 100%;float: right;background: blue;text-align: center;}.center {height: 100%;margin-left: 100px;margin-right: 100px;background: oldlace;}</style><div class="container"><div class="left">left固定</div><div class="right">right固定</div><div class="center">中间自适应</div></div>

浮动+BFC

<style>.container {width: 500px;height: 200px;line-height: 200px;}.left {width: 100px;height: 100%;float: left;background: orange;text-align: center;}.right {width: 100px;height: 100%;float: right;background: blue;text-align: center;}.center {height: 100%;/* 触发BFC */overflow: hidden;background: oldlace;text-align: center;}</style><div class="container"><div class="left">left固定</div><div class="right">right固定</div><div class="center">中间自适应</div></div>

flex

<style>.container {width: 500px;height: 200px;line-height: 200px;display: flex;}.left {width: 100px;height: 100%;float: left;background: orange;text-align: center;}.right {width: 100px;height: 100%;float: right;background: blue;text-align: center;}.center {height: 100%;flex: 1;background: oldlace;text-align: center;}</style><div class="container"><div class="left">left固定</div><div class="center">中间自适应</div><div class="right">right固定</div></div>

table布局

注意容器的顺序

<style>.container {width: 500px;height: 200px;line-height: 200px;display: table;}.left {width: 100px;height: 100%;display: table-cell;background: orange;text-align: center;}.right {width: 100px;height: 100%;display: table-cell;background: blue;text-align: center;}.center {height: 100%;display: table-cell;background: oldlace;text-align: center;}</style><div class="container"><div class="left">left固定</div><div class="center">中间自适应</div><div class="right">right固定</div></div>

定位

<style>.container {width: 500px;height: 200px;line-height: 200px;position: relative;}.left {width: 100px;height: 100%;background: orange;text-align: center;position: absolute;left: 0;}.right {width: 100px;height: 100%;background: blue;text-align: center;position: absolute;right: 0;}.center {height: 100%;background: oldlace;text-align: center;margin: 0 100px;}</style><div class="container"><div class="left">left固定</div><div class="right">right固定</div><div class="center">中间自适应</div></div>

更多推荐

CSS 三栏布局

本文发布于:2023-12-06 00:06:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1665825.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布局   CSS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!