惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threatpost
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
S
SegmentFault 最新的问题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 司徒正美
T
Tailwind CSS Blog
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
PCI Perspectives
PCI Perspectives
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
TaoSecurity Blog
TaoSecurity Blog
云风的 BLOG
云风的 BLOG
C
Cybersecurity and Infrastructure Security Agency CISA
O
OpenAI News
Recorded Future
Recorded Future
GbyAI
GbyAI
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Y
Y Combinator Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
量子位
博客园 - 叶小钗
V
Vulnerabilities – Threatpost
F
Full Disclosure
Recent Announcements
Recent Announcements
Vercel News
Vercel News
S
Schneier on Security
H
Heimdal Security Blog
Cisco Talos Blog
Cisco Talos Blog
V2EX - 技术
V2EX - 技术
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
B
Blog RSS Feed
宝玉的分享
宝玉的分享
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy & Cybersecurity Law Blog
T
Threat Research - Cisco Blogs
G
Google Developers Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
爱范儿
爱范儿
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
N
Netflix TechBlog - Medium
S
Security @ Cisco Blogs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cyberwarzone
Cyberwarzone

博客园 - 小虫1

AI 视频修复技术落地对比:四款去水印工具的技术路线解析 浏览器端本地视频处理实测:4 种去水印方案的技术原理与效果对比 前端开发者视角:一个视频去水印工具的技术猜想 记一次本地视频去水印踩坑经历——从本地部署到在线工具 前端实现视频去水印的几种技术方案对比 豆包视频去水印工具横向测评:麻雀 AI 工具箱与 3 款海外工具实测对比 视频去水印工具实战横评:少谈“黑科技”,多聊实际能用的 2026 在线视频去水印工具实测:4 种方案对比,本地处理首选麻雀AI工具箱 豆包生成的图片,怎么去水印? 2026年,GEO到底怎么做?-麻雀GEO Topaz Video AI的替代品 -麻雀AI视频修复工具,免费、安全、高效的Topaz替代选择 视频清晰度增强网站-麻雀AI视频修复工具 vue2 函数式调用一个弹框组件 跟框架无关的前端换皮肤 前端请求跨域,解决方案 ssh2-sftp-client 上传文件至服务器 vue项目下自己封装上传文件功能 beego 注册路由失效404,commentsRouter.go没有生成 前端代码实现整体缩放网页,做到缩放分辨率的效果 前端 docker jenkins mkdocs生成的网站为何很慢 重新搞nginx vue公共布局组件Layout引入 重新认识布局:html和body元素 重新认识布局:3d空间中的css盒子 重新认识布局:百分比单位 重新认识布局:标准流,浮动,定位的关系 微信小程序 等宽不等高瀑布流
重新认识布局:你真的懂flex吗
小虫1 · 2021-06-25 · via 博客园 - 小虫1

本文首发于知乎:https://www.zhihu.com/people/xiao-chong-10-60

1.flex布局,里面的flex项目会脱标吗?
flex布局经常被拿来和浮动比较。但这里要明确:2者都能使得盒子横向排列之外,他们之间几无关联。
浮动的元素会脱标,父元素要有高度,我们得清除浮动。flex布局并不会脱标。这个所有的资料里并没仔细对比,但又很重要。
比如:做一个九宫格,同样的结构,浮动和flex布局的写法不一样,浮动是脱标的,左右,上下的边框加粗的问题,可以用margin负值搞定。看下面的例子,怎么解决边框加粗的问题?水平方向上:margin-left:-1px;竖直方向上:margin-top:-1px;

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<style>
		/* 任务:做一个九宫格,3*3的样式,每个格子大小为60px*60px */
		* {
			padding: 0;
			margin: 0;
			box-sizing: border-box;
		}

		li {
			list-style: none;
		}

		ul {
			width: 180px;
			height: 180px;
			margin: 10px auto;
		}

		ul li {
			float: left;
			width: 60px;
			height: 60px;
			background-color: pink;
			text-align: center;
			line-height: 60px;
			border: 1px solid #000;
			margin-left: -1px;
			margin-top: -1px;
		}
	</style>
</head>

<body>
	<ul>
		<li>1</li>
		<li>2</li>
		<li>3</li>
		<li>4</li>
		<li>5</li>
		<li>6</li>
		<li>7</li>
		<li>8</li>
		<li>9</li>
	</ul>
</body>

</html>


假设我们用flex做呢,边框加粗的问题还能用浮动一样的做法吗?答案是不行。浮动是脱标的,flex并不是,浏览器绘制盒子的过程有区别。水平方向上的边框加粗用margin-left:-1px可以解决,竖直方向上用margin-top:-1px:不行。
怎么办呢,让第二行的上下边框都去掉。

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<style>
		/* 任务:做一个九宫格,3*3的样式,每个格子大小为60px*60px */
		* {
			padding: 0;
			margin: 0;
			box-sizing: border-box;
		}

		li {
			list-style: none;
		}

		ul {
			display: flex;
			flex-wrap: wrap;
			width: 180px;
			height: 180px;
			margin: 10px auto;
		}

		ul li {
			width: 60px;
			height: 60px;
			background-color: pink;
			text-align: center;
			line-height: 60px;
			border: 1px solid #000;
			margin-left: -1px;
		}

		.second-row {
			border-top: 0;
			border-bottom: 0;
		}
	</style>
</head>

<body>
	<ul>
		<li>1</li>
		<li>2</li>
		<li>3</li>
		<li class="second-row">4</li>
		<li class="second-row">5</li>
		<li class="second-row">6</li>
		<li class="third-row">7</li>
		<li class="third-row">8</li>
		<li class="third-row">9</li>
	</ul>
</body>

</html>


2.flex布局,剩余的空间会占满吗?
并不会,剩余的空间分配,主轴上,由子项目的flex属性指定。侧轴会占满父盒子。请看下面的例子:

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<style>
		.box {
			display: flex;
			width: 1000px;
			height: 200px;
			background-color: pink;
		}

		.box .left {
			width: 200px;
			height: 100px;
			background-color: purple;
		}

		.box .right {
			background-color: skyblue;
		}
	</style>
</head>

<body>
	<div class="box">
		<div class="left">我设置了宽高</div>
		<div class="right">我宽高都没设置</div>
	</div>
</body>

</html>