我无法更改从Google Fonts复制的字体样式的字体大小。

3

无论设置什么字体大小,'Flavoroso'的字体大小都不会改变。请问有人能帮我解决这个问题吗?

HTML

<!DOCTYPE html>
<html>
    <head>
        <title>Main Page</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="index.css">
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Dancing+Script">
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
    </head>

    <body>
        <div class="container align-items-center d-flex h-100">
          <header class="text-center col-12">
              <h1>Flavoroso</h1>
          </header>
        </div>
    </body>
</html>

CSS(层叠样式表)
h1 {
  background-color: rgb(167, 166, 165, 0.5);
  font-family: "Dancing Script", cursive;
  font-style: italic;
  font-size: 7rem;
  color: rgb(29 28 28);
}

我尝试运行你的代码,看起来工作正常。问题可能是由于 CSS 导入不当引起的,或者还存在其他字体大小等问题。 - Salil Rajkarnikar
1
尝试这样做:将Bootstrap CDN和Google字体放在原始样式表之前。 - user14925601
1
@DevChaudhary 是的先生。您的解决方案起作用了。非常感谢您 :) - Arpitha Prakash
4个回答

5
在 head 标签中,尝试先链接 Bootstrap,然后是 Google 字体,最后是你的 CSS 文件。顺序非常重要,始终将 CSS 链接放在最后。

2

你的代码应该像这样。

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

    <title>Hello, world!</title>
    <style>
        h1 {
  background-color: rgb(167, 166, 165, 0.5);
  font-family: "Dancing Script", cursive;
  font-style: italic;
  font-size: 7rem;
  color: rgb(29 28 28);
}
    </style>
  </head>
  <body>
    <div class="container align-items-center d-flex h-100">
        <header class="text-center col-12">
            <h1>Flavoroso</h1>
        </header>
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Dancing+Script">

  </body>
</html>

请问这对您是否可行?

1
你的代码看起来没问题。问题可能是由于不正确的CSS导入引起的。请使用以下代码代替。
<!DOCTYPE html>
<html>
    <head>
        <title>Main Page</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="index.css">
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Dancing+Script">
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
        <style>
            h1 {
                background-color: rgb(167, 166, 165, 0.5);
                font-family: "Dancing Script", cursive;
                font-style: italic;
                font-size: 3rem;
                color: rgb(29 28 28);
            }
</style>
    </head>

    <body>
        <div class="container align-items-center d-flex h-100">
          <header class="text-center col-12">
              <h1>Flavoroso</h1>
          </header>
        </div>
    </body>
</html>

0

我相信Bootstrap和你的本地样式之间存在冲突。你可以给标题标签添加一个class属性,并使用类名来进行样式设置(以增加特定性)。

代码示例

/*overriding bootstrap style by using a class name*/
.anyClassName {
  background-color: rgb(167, 166, 165, 0.5);
  font-family: "Dancing Script", cursive;
  font-style: italic;
  font-size: 7rem;
  color: rgb(29 28 28);
  font-size: 7rem;
}
<!DOCTYPE html>
<html>
    <head>
        <title>Main Page</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="index.css">
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Dancing+Script">
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
    </head>

    <body>
        <div class="container align-items-center d-flex h-100">
          <header class="text-center col-12">
          <!-- Adding class name of your preference here -->
              <h1 class="anyClassName">Flavoroso</h1>
          </header>
        </div>
    </body>
</html>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接