- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
下面的第三个 flex 元素有一个非零值的 flex-grow
,即 0.1
。这可能是合理的,我还读到一个建议,它应该占用任何额外空间的 100%,因为其他 flex 元素是 0
,并且不能增长。这个是 0.1
甚至 0.1/0.1
也是 100%(作为比率)。然而,实际上在 Chrome 和 Firefox 上它只占用了 10% 的额外空间。它为什么以及应该如何表现?
#container {
display: flex;
border: 1px dashed blue
}
#container div {
border: 1px dashed orange
}
#container div:last-child {
flex-grow: 0.1;
background: #ccc
}
<div id="container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
最佳答案
However, in practice on Chrome and Firefox it only took 10% of the extra space.
这是正确的行为。
Find the ratio of the item’s flex grow factor to the sum of the flex grow factors of all unfrozen items on the line. Set the item’s target main size to its flex base size plus a fraction of the remaining free space proportional to the ratio. flexbox-ref
从上面可以看出,flex-grow
值有效的表示了空闲空间的百分比,flex-grow: 1
代表了100%的空闲空间。另外,加入flex-grow
后的大小也是由这样的等式推导出来的。
flex item's base size + (remaining free space * (flex item's flex factors / unfrozen flex item's flex factors))
如果您在问题的上下文中为 flex-grow
指定 0.1,剩余可用空间 将是 初始可用空间 的 0.1 倍:
If the sum of the unfrozen flex items’ flex factors is less than one, multiply the initial free space by this sum. If the magnitude of this value is less than the magnitude of the remaining free space, use this as the remaining free space. flexbox-ref
因此,使用上面的公式,第三个 flex 元素的大小可以推导如下:
flex item's base size + (initial free space * 0.1 * (0.1 / 0.1))
= flex item's base size + (initial free space * 0.1)
因此 flex-grow: 0.1
的结果是初始剩余可用空间的 10%。
关于css - 在 CSS3 中,flex-grow 为 0.1 的 flex 元素应该占用所有额外空间还是只占用 10%?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59574099/
我正在尝试编写一个Android应用程序,它可以不断地在随机位置绘制圆圈。这已经在我的代码中完成了。我的下一个目标是慢慢地制作这些圆圈的动画,使它们“生长”到屏幕上。基本上将圆的半径从 0 增加到 3
有一个棘手的小问题:/我有一个绝对定位的 div,它没有宽度,因为内容是动态创建的。 在这个 div 中有另一个绝对定位的 div,同样没有宽度,因为内容是动态创建的。 在这个 div 中有两个动态创
我正在创建一个时间线,它的线上有圆圈表示不同的事件。当用户将鼠标悬停在圆圈上时,我想要一条线从圆圈中“长出”,最后是事件文本。有没有人对使用什么来使这种效果成为可能有任何建议。 Javascript?
初级程序员在这里。下面的代码似乎总是遇到一个错误,称为:“未分配正在释放的指针”,我不明白为什么。 结构包含动态数组,用于在读取文件后存储整数和字符串。此文件包含城市名称、高温和低温的列表。然后,在读
要解释正在发生的事情有点棘手。 http://easyuniv.com/staging/gonzaga/ 如果您访问我上面的站点,您可以看到当窗口水平收缩和扩展时背景图像如何移动。我希望做到这一点,无
我正在用 C++ 创建一个素数生成器,使用一个数组来存储我找到的素数,然后使用它们来检查势能。有没有办法在我的程序继续时“增加”我的阵列? 最佳答案 参见 std:vector。 http://new
我正在基于同一行上的两个列表构建导航。两个列表中的所有元素之间都应该有间距,但 25px最多。 flex-grow 的问题: 如果我使用 flex-grow,元素会变得大于它们自己的宽度 + 25px
我刚刚熟悉 Flex 框,当我将 flex-grow:1 应用于一组列时,它似乎使列高度均匀增长,但不是我的目标宽度。 如果我理解这一点,默认的 flex-direction 是“行”……所以理论上宽
我有两个使用 flex-grow 的“拆分”,如果只有一个存在则为 100%,如果两个都存在则为 50%/50%。问题是我希望此行为取决于 div.split 中内容的存在。 通过一些摆弄,我可以让它
HTML:
我有一个 ul 容器和 li 菜单项。容器是 100% 宽度,li 元素是父元素的 50% 宽度。 Parent 设置为显示 flex,flex 方向为 column。现在这些元素是 flex par
我试图让 views-cntnr 占用 views-cntnr 和 menubar div 未使用的任何空间。为此,我将 flex 显示设置为列方向。然后我将 views-cntnr 的 flex-g
我试图让 views-cntnr 占用 views-cntnr 和 menubar div 未使用的任何空间。为此,我将 flex 显示设置为列方向。然后我将 views-cntnr 的 flex-g
这个问题在这里已经有了答案: Targeting flex items on the last or specific row (10 个答案) 关闭 4 年前。 所以我有一个包含一些盒子的 fle
目前,我正在尝试列一个 list 。在适合我的“显示 flex 布局”并在所有浏览器上调整大小的左侧图像。我的“flex 增长布局”列表 1 用于图像,3 用于描述。没有图像,一切都很好,但是对于我的
我正在创建一个具有 2 列布局或 3 列布局的响应式网站。 我正在使用 flex-box,因为我想为它们设置顺序。 我希望方框能填满最大可用空间。 Flexbox 工作完美,除了图像不会按比例调整大小
我有一个像这样的简单页面 Header Content Footer Dialog CSS: main { display: flex; flex-direct
如果我有一个包含 2 个垂直 div 的固定高度 div,我希望第一个 div 是内容的高度,最多为父 div 的 80%,此时它的内容将在其余部分滚动它的。第二个 div 应该增长到父容器的其余部分
我想知道是什么定义了一个内存对象的开始地址是比对象的结束地址低还是高。例如: char buffer[10]; char* p = &buffer[0]; printf("%p\n",p); //0x
我有一段代码想在多线程中运行,但是当我增加要运行的线程数时,我并没有得到太多加速。在一个点之后,我遇到的线程越多,它就越糟糕,以至于比顺序运行更糟糕。 所以我想知道可能是什么问题,我想知道 Open
我是一名优秀的程序员,十分优秀!