使用 CDN 链接和 SCSS 覆盖引导程序 4



我在这里看到的关于用SCSS覆盖Bootstrap(v4(的所有答案都假设Bootstrap(或Bootstrap的CSS文件?(被下载到站点目录。

我正在通过 CDN 链接将引导程序导入我的布局.html页面,并在它之后链接到所有其他 CSS 文件。与SCSS链接的那个被列在最后。我会以这种方式链接以覆盖带有 SCSS 的引导程序。

举个简单的例子,我无法更改用作每个页面标题的字体。layout.html中的部分是这样的:

<head>
<!-- Bootstrap 4 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<!-- Fontawesome -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=IM+Fell+English+SC" rel="stylesheet">
<!-- Additional CSS use of static dir structure require w/ jinja-->
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
</head>
<body>
<div class="container siteTitle h-100">
<div class="row h-100 mx-auto">
<div class="col-md-12" >
<h1 id="siteName">Foo</h1>
<h3 id="siteSubTitle">Bar</h3>
<h6 id="siteTagLine">Baz</h6>
</div>
</div>
</div> <!-- end header container -->
</body>

SCSS目前看起来像这样:

$siteFont: 'IM Fell English SC', serif;

#siteName, #siteSubTitle, #siteTagLine {
$font-family-serif: $siteFont !default;
}

已经尝试了其他变体(例如,放弃$siteFont变量并将字体名称直接放在CSS规则中(。我该如何做到这一点?

所以对此的简短回答是 - 你不能。

也就是说,您不能更改任何 SASS 变量,但仍从 CDN 使用 Bootstrap。这是因为该版本的 Bootstrap 已经被编译,所以变量(例如 $font-family-base 或 $enable-response-font-size(已经被替换了。

如上面的讨论,如果你想改变任何 SASS 变量,你需要编译你自己的 Bootstrap 版本。

对于简单的更改,这当然感觉有点矫枉过正。因此,继续使用 CDN 版本并在 CSS 级别覆盖内容并没有错。对于更广泛的变化,SASS当然是要走的路。

最新更新