- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
此链接 ( https://css-tricks.com/snippets/css/a-guide-to-flexbox/ ) 表示 justify-content
和 align-content
的默认值是 flex-start
和 stretch
追溯。
MDN ( https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content & https://developer.mozilla.org/en-US/docs/Web/CSS/align-content ) 表示这些属性的默认值为 normal
。
哪个是正确的?/我该如何解释?
最佳答案
更准确地说,默认值实际上称为初始值,这是正确的词。考虑到两者具有完全相同的含义,我将在我的回答中同时使用它们
您需要考虑规范才能找到它,您需要注意,因为有两个规范定义了它。
first one related to flexbox (您必须遵循的那个)为 justify-content
提供初始值作为 flex-start
为 align-items 提供
。这是 Flexbox Level 1 规范,并得到广泛支持。stretch
第二个相关to future alignment techniques .该规范仍处于草案模式,将定义在不同上下文(Flexbox/Grid/Block/multicol/.. 容器)中对齐元素的新方法。这两个属性(justify-content
和 align-items
)的默认值为 normal
如果继续阅读,您会发现 normal
将回退到 flexbox 上下文中的 stretch
和 justify-content
stretch
表现为 flex-start
因此在所有情况下,可以安全地假设 justify-content
的初始值为 flex-start
,因为 normal
将回退到它(与 align-items
相同,您可以将 stretch
视为默认值)
换句话说,normal
是一个特殊的关键字(例如 auto
),它会根据上下文有不同的行为。所以我们无法真正定义 normal
会做什么。我们只能在特定上下文(Flexbox/Grid/Block/multicol/.. 容器)中针对每个属性执行此操作。
您也可以毫无问题地使用normal
,因为它会:
初始
值(flex-start
或stretch
在 Flexbox 规范中定义)无论使用何种浏览器,您都将获得相同结果的示例:
.box {
display:inline-flex;
width:200px;
height:200px;
border:1px solid;
justify-content:normal;
align-items:normal;
}
.not-normal {
justify-content:flex-start;
align-items:stretch;
}
.initial {
justify-content:initial;
align-items:initial;
}
.box span {
background:red;
padding:10px;
}
<p>using normal</p>
<div class="box"><span> some text here</span></div>
<div class="box" style="flex-direction:column;"><span> some text here</span></div>
<p>using flex-start/stretch</p>
<div class="box not-normal"><span> some text here</span></div>
<div class="box not-normal" style="flex-direction:column;"><span> some text here</span></div>
<p>using initial</p>
<div class="box not-normal"><span> some text here</span></div>
<div class="box not-normal" style="flex-direction:column;"><span> some text here</span></div>
MDN 有点令人困惑,因为它将两个规范组合在一起,因此很难理解,但您可以清楚地看到它在末尾链接到两个规范:https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content#Specifications .关注他们以获得更准确的细节(可能有点无聊,但请耐心等待..)
了解 MDN 如何误导的相关问题:
How does justify-items work on display:block elements
Flexbox in responsive table layout: Column not stretching to full height
关于html - justify-content 和 align content 的默认值是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62350959/
我试图找出在表格单元格上放置对齐属性与使用 text-align css 属性之间的区别。下面的代码显示了 IE 与其他浏览器中的不同结果。在 IE 中,对齐最终会对齐每个子子项,因此文本“test”
我正在 summernote HTML 编辑器上做一些 POC,我正在使用自定义工具栏,但我不知道如何添加对齐(左对齐、居中对齐、右对齐)工具栏,所以有人可以帮助我实现这一目标。 还有人可以帮我找到更
以下是从节对齐转换为文件对齐的步骤: 找到数据的 RVA 从 RVA 导出引用的数据所属的部分。这是微不足道的,因为部分不重叠。文件头中提供了各个部分的起始地址。 找出RVA和section的起始地址
align-self 在以下代码中, align-self 与 flex-wrap: nowrap 一起使用。 flex-container { display: flex; flex-wra
这是CSS: .divPhoto { border:1px solid #999; width:140px; height:140px; border-radius:3
我正在为 Windows Phone 8 开发,我已经设计了我的应用程序,我注意到有一个“分配网格”代码,默认情况下可以在新项目中取消注释。 看看下面的文件中的描述: --> 这是取
我们有浏览器前缀或黑客 (for Google and Safari) text-align: -webkit-right; (for Firefox) text-align:
最近我观察到,在 Clang 9.0 上 alignof 和 __alignof 为 unsigned long long 返回不同的值,并且在 https://reviews.llvm.org/D5
我已经一年多没有为 Android 开发了,我对它有点生疏了。我正在尝试设置一个有点简单的 UI:屏幕底部的底部栏和它上面的 fragment (但没有填充整个高度)。像这样: 我认为这会很简单,但经
你好,我正在尝试找到一种使用“讨厌的”align=center 技巧的方法.. 嗯,当我查看一些代码时,我注意到两个非常相似的片段呈现的并不相同。我找不到让他们表现相同的方法。这包括用 div 替换顶
抱歉这个愚蠢的问题。我只想知道我们什么时候讨论内存中的数据应该如何对齐之类的。这个主题是叫“内存对齐”还是“数据对齐”,还是我可以随便叫它什么? 最佳答案 在编程的上下文中,它被称为 data str
所以我只是想制作一个简单的导航栏,并且我刚开始使用 flexbox。为什么 align-content 在这里不起作用?我可以让 justify-content 工作,但我就是无法垂直对齐。这是代码。
我从这个 SO 开始答案,我试图使用提供的纯 flexbox 答案。 然而,当我尝试这个时,我看到了以下结果。 我不确定为什么 Button 4 在行中出现的位置高于其余元素。 HTML
我已通读 A complete guide to Grid ,但仍然对两组容器属性之间的差异感到困惑,即“justify/align-items”与“justify/align-content”。 我
我有一个simple plunker here. .container { display:flex; flex-flow: row nowrap; justify-content: sp
从 http://code.google.com/p/berkeleyaligner/ 下载主干代码后,我将该项目添加到 Eclipse 上的构建路径中。然后,使用下面的代码,我可以提取从 sourc
这个问题在这里已经有了答案: What's the difference between align-content and align-items? (15 个答案) 关闭 7 年前。 我发现 C
[short text][image1][image2]____________________________________ [this is a reallyyyyyyy............
我有一个很小的菜单列表,当鼠标靠近时它应该会增长。在其原始状态下,菜单是右对齐的,悬停时每第二个元素向右移动并左对齐以为增加的高度腾出空间(参见 JSFiddle )。 ul { font-siz
这个问题在这里已经有了答案: Align child elements of different blocks (3 个答案) 关闭 3 年前。
我是一名优秀的程序员,十分优秀!