0

I'm a fresher in Web Development field, and I've taken Angela Yu's Web development bootcamp. I'm currently using bootstrap v5 , html5 , CSS3

I came across a problem, I couldn't change properties of body tag when I target using Tag selection

Here's my index.html

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>TinDog</title>

  <!-- External style Sheet -->
  <link rel="stylesheet" href="css/styles.css">

  <!-- bootstrap -->
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>
  <!-- Google fonts -->
  <link rel="preconnect" href="https://fonts.gstatic.com">
  <link href="https://fonts.googleapis.com/css2?family=Montserrat&family=Ubuntu:wght@500&display=swap" rel="stylesheet">
  <!-- font awesome -->
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.3/css/all.css" integrity="sha384-SZXxX4whJ79/gErwcOYf+zWLeJdY/qpuqC4cAa9rOGUstPomtqpuNWT9wdPEn2fk" crossorigin="anonymous">
</head>

<body>
  <section id="title">
    <!-- Nav Bar -->
    <nav class="navbar navbar-expand-lg navbar-dark">
      <div class="container-fluid p-0 title-container">
        <a href="#" class="navbar-brand">tinCat</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
          <ul class="nav navbar-nav">
            <li class="nav-item"><a class="nav-link" href="">Contact</a></li>
            <li class="nav-item"><a class="nav-link" href="">Pricing</a></li>
            <li class="nav-item"><a class="nav-link" href="">Download</a></li>

          </ul>
        </div>
      </div>

    </nav>
    <!-- Nav Bar end -->


    <!-- Download Section -->
    <div class="container-fluid p-0 title-things">
      <div class="row">
        <div class="col-lg-6 ">
          <h1>Meet new and interesting cats nearby.</h1>
          <button type="button" class="btn btn-light download-button"><i class="fab fa-apple"></i> Download</button>
          <button type="button" class="btn btn-dark download-button"><i class="fab fa-google-play"></i> Download</button>
        </div>
        <div class="col-lg-2">
          <img class="cat-profile"src="images/iphone6.png" alt="iphone-mockup">
        </div>
      </div>

  </section>
  </div>



</body>

</html>

Here's my Styles.css

body{
  font-family: 'Montserrat', sans-serif;
 
}

#title{
  padding: 3% 15%;
  background-color: #ff4c68;
  font-family: 'Montserrat', sans-serif;
  color: #ffffff;
}
.navbar-brand{
  font-family: 'Ubuntu', sans-serif;
  font-weight: bold;
  font-size: 2.5rem !important;

}

.cat-profile
{
  transform: rotate(10deg);
  width: 360px;
  margin-top: 20px;
}

.download-button{
  margin-top:  20px;

}

.title-things{
  margin-top: 100px ;
}

.title-container {
padding: 0% 15%;
}

/* .col{
  padding: 0px;
} */
/* .title-text
{
font-family: 'Montserrat', sans-serif;
font-weight: bold;
size : 3rem;
line-height: 1.5;
} */

Conversely I added a new class to the tag and in External Style sheet, I targeted it using Class selector and it worked! Can someone explain why?

2
  • 1
    You should not use !important unless you really have to. This looks like you are importing your style sheets first. This way they might be overwritten by bootstraps styles. Try to include your custom styles after bootstrap css. Commented Apr 28, 2021 at 16:04
  • Yeah, I just started leaning it for 2 days, This is the thing that I wanted to know, We have to link stylesheet at last which gives it the best importance. Thankss Commented Apr 28, 2021 at 23:35

2 Answers 2

3

It all depends on the order that your styles appear, so if you add your styles below bootstrap it will override bootstrap styles . Change code like this ,

        <!-- bootstrap -->
        <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
        <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>
        <!-- Google fonts -->
        <link rel="preconnect" href="https://fonts.gstatic.com">
        <link href="https://fonts.googleapis.com/css2?family=Montserrat&family=Ubuntu:wght@500&display=swap" rel="stylesheet">
        <!-- font awesome -->
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.3/css/all.css" integrity="sha384-SZXxX4whJ79/gErwcOYf+zWLeJdY/qpuqC4cAa9rOGUstPomtqpuNWT9wdPEn2fk" crossorigin="anonymous">

       <!-- External style Sheet -->
      <link rel="stylesheet" href="css/styles.css">
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, It worked for me, I'd had a hard time figuring out this thing, why it doesn't override, Again Thanks!
1

Put your stylesheet below the others

          <head>
            <meta charset="utf-8">
            <title>TinDog</title>

            <!-- bootstrap -->
            <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
            <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>
            <!-- Google fonts -->
            <link rel="preconnect" href="https://fonts.gstatic.com">
            <link href="https://fonts.googleapis.com/css2?family=Montserrat&family=Ubuntu:wght@500&display=swap" rel="stylesheet">
            <!-- font awesome -->
            <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.3/css/all.css" integrity="sha384-SZXxX4whJ79/gErwcOYf+zWLeJdY/qpuqC4cAa9rOGUstPomtqpuNWT9wdPEn2fk" crossorigin="anonymous">

          <!-- External style Sheet -->
          <link rel="stylesheet" href="css/styles.css">
          </head>

1 Comment

Thank you So much! I came to know this stuff just now!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.