【发布时间】:2020-12-25 02:18:30
【问题描述】:
我是前端新手,我正在尝试了解如何智能地使用类(bem 和 sass)。
我觉得我非常依赖 mixins。几天前我出于好奇看了一下 Bootstrap,并注意到像 flex 之类的类(每个媒体查询一个类)直接应用在 html 标记中。
就我而言,我习惯于在 mixin 中使用 flex 并将其包含在 SCSS 中。
我的混音:
@mixin d-flex($direction, $justify, $align) {
display: flex;
align-items: $align;
justify-content: $justify;
flex-direction: $direction;
}
我的方法:(一段scss):
.introduction {
@include d-flex(column, center, left); //direction, justify, align
background-image: linear-gradient(rgba(177, 174, 174, 0.5), rgb(0, 0, 0)), url("../images/header_samus.png");
background-size: cover;
background-repeat: no-repeat;
font-weight: 700;
width: 100%;
height: 90vh;
@include tablet{
height:70vh;
}
}
在 bootstrap 中,它使用已经定义的类并直接在 html 标签中应用它们。
<div class="d-flex p-2">I'm a flexbox container!</div>
我的方法正确吗?或者我是否必须为每个媒体查询准备预定义的类并将它们直接添加到 html 标记中,就像 就像引导示例?
谢谢!
【问题讨论】:
标签: css twitter-bootstrap sass flexbox bem