怎么用css实现两列布局(css,开发技术)

时间:2024-04-28 08:48:26 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

两列布局

经典的两列布局左右两列组成,其特点为一列宽度固定另一列宽度自适应两列高度固定且相等。以下以左列宽度固定和右列宽度自适应为例,反之同理。

怎么用css实现两列布局

<divclass="two-column-layout"><divclass="left"></div><divclass="right"></div></div>

float + margin-left/right

左列声明float:left和固定宽度,由于float使节点脱流,右列需声明margin-left为左列宽度,以保证两列不会重叠。

.two-column-layout{width:400px;height:400px;.left{float:left;width:100px;height:100%;background-color:#f66;}.right{margin-left:100px;height:100%;background-color:#66f;}}

overflow + float

左列声明同上,右列声明overflow:hidden使其形成BFC区域与外界隔离。

.two-column-layout{width:400px;height:400px;.left{float:left;width:100px;height:100%;background-color:#f66;}.right{overflow:hidden;height:100%;background-color:#66f;}}

flex

使用flex实现会更简洁。左列声明固定宽度,右列声明flex:1自适应宽度。

.two-column-layout{width:400px;height:400px;.left{float:left;width:100px;height:100%;background-color:#f66;}.right{overflow:hidden;height:100%;background-color:#66f;}}
 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:怎么用css实现两列布局的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:BIOM微生物数据格式及文件转换的方法下一篇:

11 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18