css - 简写 flex 和 flex-basis 属性之间的区别
问题描述
flex
在使用和时,我看到 HTML 元素发生了两种不同的情况flex-basis
。下面的第二个示例使用flex-basis & flex
, 与第一个示例有何不同,仅使用flex
?
.row {
display: flex;
flex-flow: row wrap;
flex: 1 1 100%; //Three values for flex: flex-grow | flex-shrink | flex-basis
}
VS
.col {
display: flex;
flex-direction: column;
flex-basis: 100%;
flex: 1;
}
解决方案
因为在您的最后一个示例flex
中将覆盖flex-basis
,因此flex-basis
将重新定义
const row = document.querySelector('.row'),
col = document.querySelector('.col')
console.log(`row: ${window.getComputedStyle(row).getPropertyValue('flex-basis')}`)
console.log(`col: ${window.getComputedStyle(col).getPropertyValue('flex-basis')}`)
section:first-child {
display: flex;
flex-flow: row wrap;
}
section:last-child {
display: flex;
flex-direction: column;
}
.row {
flex: 1 1 100%;
}
.col {
flex-basis: 100%;
/*this will be flex-grow:1 flex-shrink: 0 flex-basis: 0% */
flex: 1;
}
<section>
<div class="row">row</div>
</section>
<section>
<div class="col">col</div>
</section>
推荐阅读
- jquery - 如何修复 mvc 中 ajax 帖子上的内部服务器错误 500
- javascript - 雪花:如何从扁平的日期字符串变量数组中插入表格?
- java - 转换一个列表的迭代
在带有 java 8 的字符串中 - http - 为什么我的自定义标题有时不存在?
- angularjs - 角标签在点击最新版本的 Chrome 时重新排序
- serilog - 如何为 .NET Core 3.0 Worker 服务设置 serilog SEQ
- java - 实现 IP 网关(在 Java 中?)
- google-maps - 如何通过“mid”参数从 Google Maps API 下载 KML 文件?
- c++ - 为什么 for 循环只取这个简单代码中的最后一个字符串?
- left-join - cx_Oracle 在左加入表两次时冻结(两个别名)