【发布时间】:2021-12-29 11:44:41
【问题描述】:
Google 字体无法与引导程序一起使用。我在我的网站上使用谷歌字体和引导程序,但谷歌字体似乎不起作用。一旦我注释掉引导 CSS,Google 字体就会再次出现。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello World</title>
<!-- Bootstrap CSS -->
<!-- Try commenting this and font will start working -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<!-- Custom CSS -->
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Hello World</h1>
</header>
<!-- Bootstrap Script -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</body>
</html>
还有 CSS:
/* Google Font Link */
@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');
body {
margin: 0;
background: -webkit-gradient(linear, left top, left bottom, from(rgb(168, 168, 168)), to(#464645)) fixed;
/* Font Family Not Working */
font-family: 'Poppins', sans-serif;
}
header{
background-color: antiquewhite;
text-align: center;
padding: 10px;
}
JSFiddle Here
尝试过的解决方案:
- Google font not working with bootstrap这对我不起作用
- 尝试谷歌搜索...没有解决方案。
【问题讨论】:
-
您是否尝试过链接问题中的第二个或第三个答案。它可能会帮助你
-
我也只是在看那些 Rana。 ... Tr0jan,我以前从未以您使用过的方式见过 Import。我只是非常习惯于完美运行的常规格式,并且是
@import url('https://fonts.googleapis.com/css?family=Roboto|Roboto+Condensed');。在此示例中,调用的字体是 Roboto 和 Roboto Condensed。 -
开发工具检查器显示引导程序正在覆盖您的样式。我相信 Bootstrap 要么是最后加载,要么是样式层次结构问题...How can I override Bootstrap CSS Styles.
-
马修的观点可能很好。特别是因为您两次调用 Bootstrap。一次在头上,一次在身体里。尝试从正文中删除该行。
-
body中的那个是给JS的,不是CSS的,所以没问题。但 Bootstrap 似乎确实优先于自定义样式。
标签: html css twitter-bootstrap google-fonts