Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
Flexbox 为绝对定位的子项带来了新行为
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
旧版 CSS 弹性盒 布局规范会将绝对定位的子元素的静态位置设置为大小为 0px x 0px 的 flex 项。最新版规范 会将这些元素完全移出流程,并根据 align 和 justify 属性设置静态位置。在撰写本文时,桌面版和 Android 版 Edge 和 Opera 39 已支持此功能。
例如,我们将对以下 HTML 应用一些定位行为。
<div class="container">
<div>
<p>In Chrome 52 and later, the green box should be centered vertically and horizontally in the red box.</p>
</div>
</div>
我们将添加如下内容:
. container {
display : flex ;
align-items : center ;
justify-content : center ;
}
. container > * {
position : absolute ;
}
在 Chrome 52 或更高版本中,嵌套的 <div> 将在容器 <div> 中居中对齐。
在不合规的浏览器中,绿色框的左上角将位于红色框的顶部中心。
如果您想在 Chrome 或任何其他浏览器中亲自试用此功能,请下载我们的示例 或访问实时演示 。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可 获得了许可,并且代码示例已根据 Apache 2.0 许可 获得了许可。有关详情,请参阅 Google 开发者网站政策 。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2016-06-16。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2016-06-16。"],[],[]]