在Bootstrap 3中我使用了这个:
.something {
padding: 5px;
@media screen and (min-width: $screen-sm-min) {
padding: 20px;
}
@media screen and (min-width: $screen-md-min) {
padding: 40px;
}
}
如何在Boostrap 4-alpha中做同样的事情?我在他们的文档中找不到一个例子。 这是变量.scss
$grid-breakpoints: (
xs: 0,
sm: 576px,
md: 768px,
lg: 992px,
xl: 1200px
) !default;
@include _assert-ascending($grid-breakpoints, "$grid-breakpoints");
@include _assert-starts-at-zero($grid-breakpoints);
答案 0 :(得分:95)
使用这样的断点mixins:
@include media-breakpoint-up(xs) { ... }
@include media-breakpoint-up(sm) { ... }
@include media-breakpoint-up(md) { ... }
@include media-breakpoint-up(lg) { ... }
@include media-breakpoint-up(xl) { ... }
v4 alpha6 breakpoints reference
低于完整选项和值。
断点& up(切换值及以上):
// Extra small devices (portrait phones, less than 576px)
// No media query since this is the default in Bootstrap
// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) { ... }
// Medium devices (tablets, 768px and up)
@media (min-width: 768px) { ... }
// Large devices (desktops, 992px and up)
@media (min-width: 992px) { ... }
// Extra large devices (large desktops, 1200px and up)
@media (min-width: 1200px) { ... }
断点&值:
@include media-breakpoint-down(xs) { ... }
@include media-breakpoint-down(sm) { ... }
@include media-breakpoint-down(md) { ... }
@include media-breakpoint-down(lg) { ... }
断点&向下(切换值和向下):
// Extra small devices (portrait phones, less than 576px)
@media (max-width: 575px) { ... }
// Small devices (landscape phones, less than 768px)
@media (max-width: 767px) { ... }
// Medium devices (tablets, less than 992px)
@media (max-width: 991px) { ... }
// Large devices (desktops, less than 1200px)
@media (max-width: 1199px) { ... }
// Extra large devices (large desktops)
// No media query since the extra-large breakpoint has no upper bound on its width
断点&下降值:
@include media-breakpoint-only(xs) { ... }
@include media-breakpoint-only(sm) { ... }
@include media-breakpoint-only(md) { ... }
@include media-breakpoint-only(lg) { ... }
@include media-breakpoint-only(xl) { ... }
仅限断点:
// Extra small devices (portrait phones, less than 576px)
@media (max-width: 575px) { ... }
// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) and (max-width: 767px) { ... }
// Medium devices (tablets, 768px and up)
@media (min-width: 768px) and (max-width: 991px) { ... }
// Large devices (desktops, 992px and up)
@media (min-width: 992px) and (max-width: 1199px) { ... }
// Extra large devices (large desktops, 1200px and up)
@media (min-width: 1200px) { ... }
仅限断点值(仅在值之间切换):
si projectco --nolock
答案 1 :(得分:9)
正如@Syden所说,mixins会起作用。另一种选择是像这样使用SASS map-get
..
@media (min-width: map-get($grid-breakpoints, sm)){
.something {
padding: 10px;
}
}
@media (min-width: map-get($grid-breakpoints, md)){
.something {
padding: 20px;
}
}
答案 2 :(得分:0)
Bootstrap提供了一种使用媒体查询为不同站点定义不同任务的方法。 它使用四个断点。
我们有超小的屏幕尺寸,小于576像素,这意味着尺寸从576到768像素。
中型屏幕尺寸占用768像素到992像素的屏幕尺寸 大屏幕,从992像素到1200像素。
例如小文本
这意味着在576px和768px之间的小屏幕上,文本居中 对于中型屏幕,将“ sm”更改为“ md”,大“ lg”更改为
答案 3 :(得分:0)
除上述之外,如果您想在模块级样式表中使用引导媒体断点(例如在 create-react-app 组件中),默认情况下它们将是未定义的,您需要导入 mixins 和将其依赖项分别放入每个模块中。
您可以在每个文件的顶部导入它们:
@import 'bootstrap/scss/_functions';
@import 'bootstrap/scss/_variables';
@import 'bootstrap/scss/mixins/_breakpoints';
或者你可以在你的 scss 文件夹中创建一个 _mixins.scss 文件,包含上面的行,然后将该文件导入模块。
注意,当你在文件名前包含“_”时,它不会被生成到 CSS 中,它会被作为一个部分文件处理,只被编译器导入并忽略。