【问题标题】:I am unable to change the font size of a font style I copied from Google Fonts我无法更改从 Google 字体复制的字体样式的字体大小
【发布时间】:2021-10-20 20:13:11
【问题描述】:

'Flavoroso' 的字体大小不会因 font-size 的任何值而改变。谁能帮我解决这个问题?

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 导入不正确,还是字体大小有其他问题?
  • 试试这个:将引导 cdn 和 googlefonts 放在原始样式表之前
  • @DevChaudhary 是的,先生。你的解决方案成功了。非常感谢:)

标签: html css fonts font-size


【解决方案1】:

在 head 标签中,尝试链接第一个引导程序,然后是 google 字体,然后是你的 css 文件。顺序很重要,总是最后链接css。

【讨论】:

    【解决方案2】:

    您的代码似乎没问题。问题可能是由于不正确的 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>
    

    【讨论】:

      【解决方案3】:

      你的代码应该是这样的。

      <!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>

      让我知道这是否适合您。

      【讨论】:

        【解决方案4】:

        我认为 bootstrap 和您的本地样式之间存在冲突。您可以在标题标签中添加一个类属性并使用类名来设置样式(以增加specificity)。

        代码示例

        /*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>

        【讨论】:

          猜你喜欢
          • 2013-10-10
          • 1970-01-01
          • 2020-02-29
          • 1970-01-01
          • 2018-08-15
          • 2011-06-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多