当前位置:网站首页>基于 flex 布局实现的三栏布局
基于 flex 布局实现的三栏布局
2022-08-02 19:36:00 【huaqi_】
基于 flex 布局实现的三栏布局
我愿称之为史上最简单(实现简单、理解简单)的三栏实现。
为什么将 div.center 作为 div.container 的首个子元素?
为了其优先加载,div.center 中一般都是存放页面的主要内容。
主要功臣是属性 order、flex。
order 属性可以自定义元素的渲染位置顺序。
flex: 1; 使该元素占据元素的剩余空间。
div.container 也没有声明 width: 100% 那为什么 div.center 会自动撑开呢?
类似 div 这种块级元素,默认 width: auto;
对于普通块级元素,其具有充分利用可用空间的特性,即 fill-available。
此时,width: 100% 属于吃力不讨好的声明。
众所周知,默认:box-sizing: content-box。此时 width 直接作用于 content-box,若声明 width: 100%,那么 padding、boder、margin 怎么办?
当然可以再声明 box-sizing: border-box,对于此,其他坏处暂且不提,同样的效果,多两行代码。
更多 CSS 相关知识见 张鑫旭《CSS 世界》。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style> .container {
display: flex; } .left {
order: 1; width: 200px; height: 300px; background-color: rgba(100, 0, 0, .6); } .center {
order: 2; flex: 1; } .right {
order: 3; width: 200px; height: 300px; background-color: rgba(100, 0, 100, .6); } </style>
</head>
<body>
<div class="container">
<div class="center">center</div>
<div class="left">left</div>
<div class="right">right</div>
</div>
</body>
</html>
边栏推荐
- Geoserver+mysql+openlayers
- J9数字货币论:识别Web3新的稀缺性:开源开发者
- 聊一聊 AS 的一些好用的功能
- golang刷leetcode 经典(10) tire树与ac自动机
- ALV报表学习总结
- 一些不错的博主
- 2022-07-28
- MOSN 反向通道详解
- 【 LeetCode 】 1374. Generate each character string is an odd number
- The so-called fighting skill again gao also afraid of the chopper - partition, depots, table, and the merits of the distributed
猜你喜欢
动态规划常见实例详解
J9数字论:互联网跨链桥有什么作用呢?
【心理学 · 人物】第一期
[安洵杯 2019]easy_web
磁盘分区的知识
Parse common methods in the Collection interface that are overridden by subclasses
LeetCode - 105. 从前序与中序遍历序列构造二叉树;023.合并K个升序链表
Gradle系列——Gradle的build.gradle文件详情,项目发布(基于Gradle文档7.5)day3-3
Shell: conditional statements
Leetcode刷题——字符串相加相关题目(415. 字符串相加、面试题 02.05. 链表求和、2. 两数相加)
随机推荐
SQL 嵌套 N 层太长太难写怎么办?
es DELETE index 源码分析
我用这一招让团队的开发效率提升了 100%!
十六进制文本的字节序问题
E - Addition and Multiplication 2(贪心)
【OpenNI2】资料整理 -- 不断更新中
geoserver+mysql+openlayers问题点
Geoserver + mysql + openlayers problem
golang刷leetcode 经典(11) 朋友圈
网络协议介绍
SQL-UDT是什么功能?
MySQL安装(详细,适合小白)
A Review of Nature Microbiology: Focusing on the Algae--Ecological Interface of Phytoplankton-Bacteria Interactions
TPAMI2022 | TransCL: based on the study the compression of the Transformer, more flexible and more powerful
Lvm逻辑卷
一款好用的FAQ搭建工具
Silver circ: letter with material life insurance products should be by the insurance company is responsible for the management
Five data structures of Redis and their corresponding usage scenarios
Caldera(二)高级实战
VMware虚拟机无法上网