css - CSS Shorthand methods for Display Flex and Flex Direction
问题描述
Is there a short hand method in CSS to combine
display:flex;
flex-direction: row / column?
into one line instead of two?
I know flex-flow
, does flex-direction and flex wrap.
解决方案
我不知道你是否精通 Sass,但是如果你精通,这是一种让你的想法发挥作用的快速方法,你也可以进一步完善这个@if
语句和@error
指令,但这里是快速简单的方法:
这是一个Codepen来演示。
混合:_
@mixin fd($flex, $direction) {
display: $flex;
flex-direction: $direction;
}
这是您包含它的方式:
@include fd([display], [direction]);
.flex-1 {
@include fd(flex, row);
// whatever goes next
}
.flex-2 {
@include fd(inline-flex, column);
// whatever goes next
}
这是它编译为:
.flex-1 {
display: flex;
flex-direction: row;
}
.flex-2 {
display: inline-flex;
flex-direction: column;
}
推荐阅读
- java - Spring Boot:禁用 Spring Boot 单元测试的安全性
- blueprism - 我已经输入了输入,但是在通过蓝色棱镜为基于浏览器的应用程序运行自动化时,单击提交再次要求输入
- java - 如何使用 PDFBox PDInlineImage
- ldap - 修复多个 slap_global_control: unrecognized control: in syslog
- java - 如何使用 Java 流从一组对象中提取不同整数的排序列表?
- android - 为什么 onBindViewHolder 中的 getItem 会为空?
- typo3 - 将自定义 CSS 类添加到 Fluid 小部件分页
- javascript - Jquery - 如何在文档区域中选择具有相同类名的 2 个元素?
- corda - 如何检查 Corda 中是否存在全局状态?
- mongodb - 如何在MongoDB中将两个顺序查询变成单个查询