-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
第 154 题:弹性盒子中 flex: 0 1 auto 表示什么意思 #380
Comments
三个参数分别对应的是 flex-grow, flex-shrink 和 flex-basis,默认值为0 1 auto。 |
.item { |
flex :flex-grow flex-shrink flex-basis ①.flex-grow 剩余空间索取 默认值为0,不索取 eg:父元素400,子元素A为100px,B为200px.则剩余空间为100 此时A的flex-grow 为1,B为2, 则A=100px+1001/3; B=200px+1002/3 ②.flex-shrink 子元素总宽度大于复制元素如何缩小 父400px,A 200px B 300px AB总宽度超出父元素100px; 如果A不减少,则flex-shrink :0,B减少; ②,flex-basis 该属性用来设置元素的宽度,当然width也可以用来设置元素的宽度,如果设置了width和flex-basis,那么flex-basis会覆盖width值。 |
flex-grow拼写错了 |
复制粘贴当自己拼写的吗? |
flex: 0 1 auto的含义大家都说的很清楚,查了一些资料补充一下以下两种情况的子元素在分配主轴空间上的计算方式 主轴空间宽度有剩余,子元素最终的宽度?<div class="parent">
<div class="item-1"></div>
<div class="item-2"></div>
<div class="item-3"></div>
</div>
<style type="text/css">
.parent {
display: flex;
width: 600px;
}
.parent > div {
height: 100px;
}
.item-1 {
width: 140px;
flex: 2 1 0%;
background: blue;
}
.item-2 {
width: 100px;
flex: 2 1 auto;
background: darkblue;
}
.item-3 {
flex: 1 1 200px;
background: lightblue;
}
</style> 主轴空间宽度不足,子元素最终的宽度?<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="container">
<div class="left"></div>
<div class="right"></div>
</div>
<style>
* {
padding: 0;
margin: 0;
}
.container {
width: 600px;
height: 300px;
display: flex;
}
.left {
/* 285 */
flex: 1 2 500px;
background: red;
}
.right {
/* 314 */
flex: 2 1 400px;
background: blue;
}
</style>
</body>
1. 总权重 500 * 2 + 400 * 1 = 1400 <br />
2. 需要缩小的宽度 <br />
left (500 * 2 / 1400) * 300 = 214.285714286<br />
right (400 * 1 / 1400) * 300 = 85.714285714<br />
3. 最后的宽度<br />
left 500 - 214.285714286 = 285.714285714<br />
right 400 - 85.714285714 = 314.285714286 <br />
</html>
|
|
flex 常用属性介绍 举例:求left right的宽度 |
flex-grow: 0; |
关于主轴宽度不够 300px 是如何计算的,求解 |
No description provided.
The text was updated successfully, but these errors were encountered: