我使用BootstrapCDN。其他样式用sass编写并由gulp构建。我需要创建自己的breakpionts。如果我使用CDN,是否可以制作它们?我无法弄清楚该怎么做。我必须创建这些断点:
--breakpoint-xxxs: 0;
--breakpoint-xxs: 320px;
--breakpoint-xs: 568px;
--breakpoint-sm: 667px;
--breakpoint-md: 768px;
--breakpoint-lg: 992px;
--breakpoint-xl: 1200px;
--breakpoint-xxl: 1440px;
--breakpoint-xxxl: 1600px;
我想得到这样的东西:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col col-xxxs-1 col-xxs-2 col-xs-3 col-sm-4 col-md-5 col-lg-6 col-xl-7 col-xxl-8 col-xxxl-9">
<div style="height:100vh;background:purple">text</div>
</div><!--col-->
</div><!--.row-->
</div><!--.container-->
我找到了the manual,我正在尝试这个:
$grid-breakpoints: (
xxxs: 0,
xxs: 320px,
xs: 568px,
sm: 667px,
md: 768px,
lg: 992px,
xl: 1200px,
xxl: 1440px,
xxxl: 1600px
) !default;
$container-max-widths: (
xxxs: 0,
xxs: 320px,
xs: 568px,
sm: 667px,
md: 768px,
lg: 992px,
xl: 1200px,
xxl: 1440px,
xxxl: 1600px
) !default;
:root {
--breakpoint-xxxs: 0;
--breakpoint-xxs: 320px;
--breakpoint-xs: 568px;
--breakpoint-sm: 667px;
--breakpoint-md: 768px;
--breakpoint-lg: 992px;
--breakpoint-xl: 1200px;
--breakpoint-xxl: 1440px;
--breakpoint-xxxl: 1600px;
}
但它不会产生结果,并产生错误:
非法嵌套:任何内容都不能嵌套在变量声明之下。
我做错了什么? 提前感谢您的帮助。
UPD:如果那是不可能的......还有其他选择吗?我可以轻松编辑我的代码以使用我的断点模拟引导网格吗?
UPD2:由于@aer0:
,我修复了错误$grid-breakpoints: (xxxs: 0, xxs: 320px, xs: 568px, sm: 667px, md: 768px, lg: 992px, xl: 1200px, xxl: 1440px, xxxl: 1600px)!default
$container-max-widths: (xxxs: 0, xxs: 320px, xs: 568px, sm: 667px, md: 768px, lg: 992px, xl: 1200px, xxl: 1440px, xxxl: 1600px)!default
\:root
--breakpoint-xxxs: 0
--breakpoint-xxs: 320px
--breakpoint-xs: 568px
--breakpoint-sm: 667px
--breakpoint-md: 768px
--breakpoint-lg: 992px
--breakpoint-xl: 1200px
--breakpoint-xxl: 1440px
--breakpoint-xxxl: 1600px
但它并没有解决我的问题。
答案 0 :(得分:14)
它无法完全从CDN完成。要使用SASS 正确自定义/覆盖,您需要在custom.scss
中@import必要的Bootstrap scss文件。要覆盖网格断点,您至少需要functions
和variables
。然后根据需要设置变量,最后设置@import bootstrap。请注意默认情况!已被删除为explained in the docs作为正确的自定义方法。
/* import what we need to override */
@import "bootstrap/functions";
@import "bootstrap/variables";
/* set the overriding variables */
$grid-breakpoints: (
xxxs: 0,
xxs: 320px,
xs: 568px,
sm: 667px,
md: 768px,
lg: 992px,
xl: 1200px,
xxl: 1440px,
xxxl: 1600px
);
$container-max-widths: (
xxxs: 0,
xxs: 320px,
xs: 568px,
sm: 667px,
md: 768px,
lg: 992px,
xl: 1200px,
xxl: 1440px,
xxxl: 1600px
);
/* override the !default vars with the values we set above */
@import "bootstrap";
通过这种方法,我们添加了新的网格断点,并确保这些新断点在Bootstrap中无处不在 ,包括网格,响应式实用程序用于间距,显示,弹性框,对齐,定位等...
https://www.codeply.com/go/BIgmm1XGc2
另见:
How to extend/modify (customize) Bootstrap 4 with SASS
Twitter Bootstrap: add media queries for xxs breakpoint
答案 1 :(得分:3)
我很惊讶没有开发人员能够回答我的问题!即使在githab,也没有人敢去想它!
事实上,一切都变得非常简单!
是的,使用CDN,我们获得了编译的css
文件。引导程序中的样式使用sass编写。而且,样式是分离和模块化的。所以这意味着我不需要将整个引导加载到我的服务器。我想提供Bootstrap的编译CSS的缓存版本,我只需要添加我的断点。幸运的是,有一个特定的bootstrap文件负责Grid。它是bootstrap-grid.scss
:
/*!
* Bootstrap Grid v4.0.0 (https://getbootstrap.com)
* Copyright 2011-2018 The Bootstrap Authors
* Copyright 2011-2018 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
@at-root {
@-ms-viewport { width: device-width; } // stylelint-disable-line at-rule-no-vendor-prefix
}
html {
box-sizing: border-box;
-ms-overflow-style: scrollbar;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
@import "functions";
@import "variables";
@import "mixins/breakpoints";
@import "mixins/grid-framework";
@import "mixins/grid";
@import "grid";
@import "utilities/display";
@import "utilities/flex";
现在我只需要按顺序添加上面添加断点的文件中的代码。不需要添加非网格代码。例如,负责颜色的代码。 Here is my mcve at codepen
答案 2 :(得分:1)
根据Github的说法,你似乎遇到了一个&#39; bug&#39;这里。见这里:https://github.com/sass/sass/issues/1166
有人说你必须把你的变量定义写成一行。
$grid-breakpoints: (xxxs: 0, xxs: 320px, xs: 568px, sm: 667px, md: 768px, lg: 992px, xl: 1200px, xxl: 1440px, xxxl: 1600px) !default
答案 3 :(得分:1)
如果只需要调整CDN引导程序的一部分而又不想重新编译,则可以仅添加相关的媒体边界。如果要添加高于-xl-(在加载bootstrap .css之后加载.css更新)或低于xs(在bootstrap之前加载.css更新)的断点,会更容易。在中间插入一个断点会比较棘手。
请参见https://www.codeply.com/p/ROF99teYDd,其中我添加了 -xxl-且从 1550px 和 -mde-开始, 840 -992px ,只需复制所需的引导媒体CSS,就在.css中。
@media (min-width: 840px) and (max-width: 992px) {
...
.col-mde-1 {
-ms-flex: 0 0 8.333333%;
flex: 0 0 8.333333%;
max-width: 8.333333%;
}
.col-mde-2 {
-ms-flex: 0 0 16.666667%;
flex: 0 0 16.666667%;
max-width: 16.666667%;
}
...
.col-mde-12 {
-ms-flex: 0 0 100%;
flex: 0 0 100%;
max-width: 100%;
}
}
@media (min-width: 1550px) {
.col-xxl-1 {
-ms-flex: 0 0 8.333333%;
flex: 0 0 8.333333%;
max-width: 8.333333%;
}
...
}
由于对插入的元素使用了最小和最大宽度,我需要为-lg-指定官方的引导程序尺寸(最小宽度:992px),以确保设计在此断点之后不会中断。
答案 4 :(得分:1)
就像我们现在已经使用CDN一样,我们获得了已编译的.css
。
面对同样的问题,做了一点CSS扩展。
在您的.css样式表中,对于每个其他断点,该断点在原始引导4个CDN .css
文件(用于覆盖容器的最大宽度)之后加载,并在下面添加代码:
/* BS4 Grid XXL breakpoint */
/* adding col-xxl */
.col-xxl, .col-xxl-1, .col-xxl-2, .col-xxl-3, .col-xxl-4, .col-xxl-5, .col-xxl-6, .col-xxl-7, .col-xxl-8, .col-xxl-9, .col-xxl-10, .col-xxl-11, .col-xxl-12, .col-xxl-auto {position: relative; width: 100%; padding-right: 15px; padding-left: 15px;}
@media (min-width: 1570px){
/* expanding BS4 max-width */
.container {max-width: 1540px;}
/* grid columns xxl */
.col-xxl {-ms-flex-preferred-size: 0; flex-basis: 0; -webkit-box-flex: 1; -ms-flex-positive: 1; flex-grow: 1; max-width: 100%;}
.col-xxl-auto {-webkit-box-flex: 0; -ms-flex: 0 0 auto; flex: 0 0 auto; width: auto; max-width: none;}
.col-xxl-1 {-webkit-box-flex: 0; -ms-flex: 0 0 8.333333%; flex: 0 0 8.333333%; max-width: 8.333333%;}
.col-xxl-2 {-webkit-box-flex: 0; -ms-flex: 0 0 16.666667%; flex: 0 0 16.666667%; max-width: 16.666667%;}
.col-xxl-3 {-webkit-box-flex: 0; -ms-flex: 0 0 25%; flex: 0 0 25%; max-width: 25%;}
.col-xxl-4 {-webkit-box-flex: 0; -ms-flex: 0 0 33.333333%; flex: 0 0 33.333333%; max-width: 33.333333%;}
.col-xxl-5 {-webkit-box-flex: 0; -ms-flex: 0 0 41.666667%; flex: 0 0 41.666667%; max-width: 41.666667%;}
.col-xxl-6 {-webkit-box-flex: 0; -ms-flex: 0 0 50%; flex: 0 0 50%; max-width: 50%;}
.col-xxl-7 {-webkit-box-flex: 0; -ms-flex: 0 0 58.333333%; flex: 0 0 58.333333%; max-width: 58.333333%;}
.col-xxl-8 {-webkit-box-flex: 0; -ms-flex: 0 0 66.666667%; flex: 0 0 66.666667%; max-width: 66.666667%;}
.col-xxl-9 {-webkit-box-flex: 0; -ms-flex: 0 0 75%; flex: 0 0 75%; max-width: 75%;}
.col-xxl-10 {-webkit-box-flex: 0; -ms-flex: 0 0 16.666667%; flex: 0 0 16.666667%; max-width: 16.666667%;}
.col-xxl-11 {-webkit-box-flex: 0; -ms-flex: 0 0 16.666667%; flex: 0 0 16.666667%; max-width: 16.666667%;}
.col-xxl-12 {-webkit-box-flex: 0; -ms-flex: 0 0 16.666667%; flex: 0 0 16.666667%; max-width: 16.666667%;}
/* order xxl */
.order-xxl-0 {-webkit-box-ordinal-group: 1; -ms-flex-order: 0; order: 0;}
.order-xxl-1 {-webkit-box-ordinal-group: 2; -ms-flex-order: 1; order: 1;}
.order-xxl-2 {-webkit-box-ordinal-group: 3; -ms-flex-order: 2; order: 2;}
.order-xxl-3 {-webkit-box-ordinal-group: 4; -ms-flex-order: 3; order: 3;}
.order-xxl-4 {-webkit-box-ordinal-group: 5; -ms-flex-order: 4; order: 4;}
.order-xxl-5 {-webkit-box-ordinal-group: 6; -ms-flex-order: 5; order: 5;}
.order-xxl-6 {-webkit-box-ordinal-group: 7; -ms-flex-order: 6; order: 6;}
.order-xxl-7 {-webkit-box-ordinal-group: 8; -ms-flex-order: 7; order: 7;}
.order-xxl-8 {-webkit-box-ordinal-group: 9; -ms-flex-order: 8; order: 8;}
.order-xxl-9 {-webkit-box-ordinal-group: 10; -ms-flex-order: 9; order: 9;}
.order-xxl-10 {-webkit-box-ordinal-group: 11; -ms-flex-order: 10; order: 10;}
.order-xxl-11 {-webkit-box-ordinal-group: 12; -ms-flex-order: 11; order: 11;}
.order-xxl-12 {-webkit-box-ordinal-group: 13; -ms-flex-order: 12; order: 12;}
/* text-align xxl */
.text-xxl-center {text-align: center!important;}
.text-xxl-left {text-align: left!important;}
.text-xxl-right {text-align: right!important;}
/* float xxl */
.float-xxl-left {float: left!important;}
.float-xxl-right {float: right!important;}
.float-xxl-none {float: none!important;}
/* display xxl */
.d-xxl-none {display: none!important;}
.d-xxl-inline {display: inline!important;}
.d-xxl-inline-block {display: inline-block!important;}
.d-xxl-block {display: block!important;}
.d-xxl-table {display: table!important;}
.d-xxl-table-cell {display: table-cell!important;}
.d-xxl-table-row {display: table-row!important;}
.d-xxl-flex {display: flex!important;}
.d-xxl-inline-flex {display: inline-flex!important;}
/* offsets xxl */
.offset-xxl-1 {margin-left: 8.333333%;}
.offset-xxl-2 {margin-left: 16.666667%;}
.offset-xxl-3 {margin-left: 25%;}
.offset-xxl-4 {margin-left: 33.333333%;}
.offset-xxl-5 {margin-left: 41.666667%;}
.offset-xxl-6 {margin-left: 50%;}
.offset-xxl-7 {margin-left: 58.333333%;}
.offset-xxl-8 {margin-left: 66.666667%;}
.offset-xxl-9 {margin-left: 75%;}
.offset-xxl-10 {margin-left: 83.333333%;}
.offset-xxl-11 {margin-left: 91.666667%;}
/* spacing xxl */
.m-xxl-0{margin:0!important}.mt-xxl-0,.my-xxl-0{margin-top:0!important}.mr-xxl-0,.mx-xxl-0{margin-right:0!important}.mb-xxl-0,.my-xxl-0{margin-bottom:0!important}.ml-xxl-0,.mx-xxl-0{margin-left:0!important}.m-xxl-1{margin:.25rem!important}.mt-xxl-1,.my-xxl-1{margin-top:.25rem!important}.mr-xxl-1,.mx-xxl-1{margin-right:.25rem!important}.mb-xxl-1,.my-xxl-1{margin-bottom:.25rem!important}.ml-xxl-1,.mx-xxl-1{margin-left:.25rem!important}.m-xxl-2{margin:.5rem!important}.mt-xxl-2,.my-xxl-2{margin-top:.5rem!important}.mr-xxl-2,.mx-xxl-2{margin-right:.5rem!important}.mb-xxl-2,.my-xxl-2{margin-bottom:.5rem!important}.ml-xxl-2,.mx-xxl-2{margin-left:.5rem!important}.m-xxl-3{margin:1rem!important}.mt-xxl-3,.my-xxl-3{margin-top:1rem!important}.mr-xxl-3,.mx-xxl-3{margin-right:1rem!important}.mb-xxl-3,.my-xxl-3{margin-bottom:1rem!important}.ml-xxl-3,.mx-xxl-3{margin-left:1rem!important}.m-xxl-4{margin:1.5rem!important}.mt-xxl-4,.my-xxl-4{margin-top:1.5rem!important}.mr-xxl-4,.mx-xxl-4{margin-right:1.5rem!important}.mb-xxl-4,.my-xxl-4{margin-bottom:1.5rem!important}.ml-xxl-4,.mx-xxl-4{margin-left:1.5rem!important}.m-xxl-5{margin:3rem!important}.mt-xxl-5,.my-xxl-5{margin-top:3rem!important}.mr-xxl-5,.mx-xxl-5{margin-right:3rem!important}.mb-xxl-5,.my-xxl-5{margin-bottom:3rem!important}.ml-xxl-5,.mx-xxl-5{margin-left:3rem!important}
.p-xxl-0{padding:0!important}.pt-xxl-0,.py-xxl-0{padding-top:0!important}.pr-xxl-0,.px-xxl-0{padding-right:0!important}.pb-xxl-0,.py-xxl-0{padding-bottom:0!important}.pl-xxl-0,.px-xxl-0{padding-left:0!important}.p-xxl-1{padding:.25rem!important}.pt-xxl-1,.py-xxl-1{padding-top:.25rem!important}.pr-xxl-1,.px-xxl-1{padding-right:.25rem!important}.pb-xxl-1,.py-xxl-1{padding-bottom:.25rem!important}.pl-xxl-1,.px-xxl-1{padding-left:.25rem!important}.p-xxl-2{padding:.5rem!important}.pt-xxl-2,.py-xxl-2{padding-top:.5rem!important}.pr-xxl-2,.px-xxl-2{padding-right:.5rem!important}.pb-xxl-2,.py-xxl-2{padding-bottom:.5rem!important}.pl-xxl-2,.px-xxl-2{padding-left:.5rem!important}.p-xxl-3{padding:1rem!important}.pt-xxl-3,.py-xxl-3{padding-top:1rem!important}.pr-xxl-3,.px-xxl-3{padding-right:1rem!important}.pb-xxl-3,.py-xxl-3{padding-bottom:1rem!important}.pl-xxl-3,.px-xxl-3{padding-left:1rem!important}.p-xxl-4{padding:1.5rem!important}.pt-xxl-4,.py-xxl-4{padding-top:1.5rem!important}.pr-xxl-4,.px-xxl-4{padding-right:1.5rem!important}.pb-xxl-4,.py-xxl-4{padding-bottom:1.5rem!important}.pl-xxl-4,.px-xxl-4{padding-left:1.5rem!important}.p-xxl-5{padding:3rem!important}.pt-xxl-5,.py-xxl-5{padding-top:3rem!important}.pr-xxl-5,.px-xxl-5{padding-right:3rem!important}.pb-xxl-5,.py-xxl-5{padding-bottom:3rem!important}.pl-xxl-5,.px-xxl-5{padding-left:3rem!important}
.m-xxl-auto{margin:auto!important}.mt-xxl-auto,.my-xxl-auto{margin-top:auto!important}.mr-xxl-auto,.mx-xxl-auto{margin-right:auto!important}.mb-xxl-auto,.my-xxl-auto{margin-bottom:auto!important}.ml-xxl-auto,.mx-xxl-auto{margin-left:auto!important}
}
现在,您将获得完全支持的XXL断点。我知道这不是最清晰的解决方案,因为我们只是覆盖Sass编译的代码。如果您有使用Sass的能力-这样做,这种方式会更正确。但是使用CDN就像quic-fix-可以使用我的解决方案。