I am unable to change the font size of a font style I copied from Google Fonts

Viewed 131

The font size of 'Flavoroso' doesn't change for any value of font-size. Can anyone help me fix this please?

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);
}
4 Answers

In the head tag, try linking first bootstrap then the google font and then your css file. The order matters a lot, always link css last.

Your code should be like this.

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

Let me know if this will work for you.

your code seems to be fine . problem may due to improper css import. Use this instead.

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

I believe there is a conflict between bootstrap and your local styles. You could add a class attribute to your heading tag and use the class name to style (in order to increase the specificity).

Code Example

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

Related