- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我的目标是使用 flexbox 创建一个双列布局,其中第一列有两行,第二列有一行,如下所示:
在第三项上设置 flex-basis: 100%
可以达到预期的效果,但前提是容器的 flex-direction
是 row
:
将 flex-direction
更改为 column
会导致以下结果,除非明确设置了 height
,这在我的元素中是不可行的:
如何在不显式设置容器的高度
的情况下获取第一张图片?
Here's a Plunker illustrating the problem .
body {
display: flex;
height: 100px;
width: 100px;
}
.container {
display: flex;
flex-direction: column; /* Setting this to `row` gives the expected effect,but rotated */
flex-grow: 1;
flex-wrap: wrap;
/* height: 100%; */ /* Setting this fixes the problem, but is infeasible for my project*/
}
.item {
flex-grow: 1;
}
.one {
background-color: red;
}
.two {
background-color: blue;
}
.three {
background-color: green;
flex-basis: 100%;
}
<div class="container">
<div class="item one"> </div>
<div class="item two"> </div>
<div class="item three"> </div>
</div>
最佳答案
为什么不起作用:
只有当 flex 元素的初始主要尺寸溢出 flex 容器时,才会发生 flex 换行。在 flex-direction: row
的情况下,这是当它们的 flex 元素比容器宽时。使用 flex-direction: column
,它们必须溢出容器的高度。
但是在 CSS 中,高度的行为与宽度有着根本的不同。 CSS 中容器的高度由其子元素的高度决定。因此,如果没有东西限制容器的高度,它们的 flex 元素将永远不会溢出;他们只是让他们的容器更高。如果它们没有溢出,它们就不会换行。
可能的解决方案:
你必须限制容器的高度。明显的方法(你说的不在讨论范围内)是设置一个显式的 height
或 max-height
。
问问自己为什么需要限制高度。是否留在视口(viewport)内?你可以使用 viewport-relative单位并设置类似 max-height: 100vh
的内容。它是否等于此 flex 容器外另一列的高度?你可以用另一个 flexbox 来约束它。使这个 flex 容器成为外部 flexbox 中的 flex 元素。不过,外部 flexbox 中的其他东西必须确定其高度。
关于html - 当 flex-direction 为 'column' 时,CSS flex-basis 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20136336/
我一直在阅读MDN article在 flex-basis css 属性。在那里我没有看到 flex-basis: auto 的任何定义.它解释了flex-basis: content .好像cont
这个问题在这里已经有了答案: What are the differences between flex-basis and width? (6 个答案) 关闭 5 年前。 我有一个容器,其中的元素
我在 flex 中有一个非常基本的网格设置,但我最近遇到了一个疏忽。 我的列有右边距:3em 和 flex-basis:calc(33% - 3em)。 我的问题是第 4 和第 5 个在有一个完整的“
如何让 flex 元素在次轴收缩? 例如,我有一个容器,里面有很多元素。它们都位于列中,但我希望它们的宽度也可以缩小: .container { display: flex; flex-dir
我有 3 个元素,我正在尝试使用 flex-basis 使它们并排占据屏幕的 20%、20% 和 60%(按此顺序),当窗口大小减小时,它们会进入专栏,问题是我的 flex-basis 什么都不做,我
(我知道这个问题在很多情况下都有详细记录,但我似乎找不到解决方法。) 问题是页面底部的 flexbox 元素高度不足 - 可能是因为这些元素中的图像加载缓慢。 这是一个例子:http://paleom
z - double 矩阵,大小为 Nx2; x - double 矩阵,大小为 Nx2; sup = x(i, :); phi(1, i) = {@(z) exp(-g * sum((z - sup
将 max-width 或 width 设置为 flex 元素而不是 flex-basis 有区别吗? 它是 flex-grow/shrink 属性的“断点”吗? 当我设置 flex-wrap: wr
刚刚学习机器学习,我正在寻找类似于 Haskell 的 const 的内置函数。它将被定义为: fun const a b = a 当然,我自己很容易实现 :) 但我认为可能有一个等效的标准功能被我忽
我想在我的项目中使用 BASYS 3 的时钟。当我搜索项目的约束时,我发现了以下代码: set_property PACKAGE_PIN W5 [get_ports clk] set_property
是否可以在 SAP 中的 RFC_READ_TABLE 的 OPTIONS 参数表中使用子查询? 像这样的东西 field in (select otherfield from othertable
我正在使用Basys mx3,并使用SSDDEMO,它在十六进制中充当计时器,我正在尝试将计时器更改为十进制,但没有成功..我该怎么做:)?非常感谢,这是 ssddemo 的链接: https://g
我为具有给定数量的粒子 N 和站点 Mtot 的 bossons 生成一个 Fock 基础(量子力学),它只是构建一组包含 Mtot 必须用N 项覆盖的地方(见下面的代码)。然后我用 M 站点 (Mt
fiddle :http://jsfiddle.net/y8d2q3ww/2/ .flex-container{display:flex;width:100%} .square{flex-basis:
我实际上找到了解决问题的方法,但想知道为什么我原来的解决方案不起作用。 我有一个简单的 flex 容器,我希望第一个 div 占容器的 30%。我给它一个 30% 的 flex-basis 来尝试实现
这个问题在这里已经有了答案: Flex-Basis for Wrapping Columns (2 个答案) 关闭 5 年前。
有一个带有 flex-direction: row 的 flex 容器。这些单独的列中的每一个都是具有 flex-direction: column 的 flex 容器。 在 flex 行中有一些表单
这个问题在这里已经有了答案: Grid with viewport height and inner scrolling div (2 个答案) 关闭 4 年前。
如何使第二列中的文本在达到列的 flex-basis 后换行?考虑到我已将 flex-basis 设置为 100px,为什么右列的宽度仍然增加? .specific-image-flexbox {
我有一个输入元素,我想使用 flex shrink 来扩大和缩小它,但它的 flex-basis 大小没有被应用。 这是我的 html: 和我的CSS: input{ background-co
我是一名优秀的程序员,十分优秀!