Unable to modify element attributes in css with tag selectors

I recently started my journey in the field of Web Development with Angela Yu's Web Development bootcamp. Currently, I am utilizing bootstrap v5, html5, and CSS3.

While working on a project, I encountered an issue where I wasn't able to modify the properties of the body tag using Tag selection. Here's a snippet of 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
  ...

</head>

<body>
  <section id="title">
    <!-- Nav Bar -->
    ...

  </section>
  </div>

</body>

</html>

Additionally, here's a snippet of my styles.css:

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

#title{
  padding: 3% 15%;
  background-color: #ff4c68;
  font-family: 'Montserrat', sans-serif;
  color: #ffffff;
}

...

Surprisingly, I applied a new class to the body tag and targeted it with the Class selector in the External Style sheet, which resolved the issue! Can anyone shed some light on the reason behind this?

Answer №1

The order in which styles are added is crucial; placing your styles below bootstrap will take precedence over bootstrap styles. Modify code as follows:

        <!-- bootstrap -->
        <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="31535e5e45424543504171041f011f011c5354455002">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
        <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="45272a2a31363137243505706b756b75682720312476">[email protected]</a>/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">

Answer №2

Make sure to place your stylesheet below all other stylesheets

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

            <!-- bootstrap -->
            <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bad8d5d5cec9cec8dbcafa8f948a948a97d8dfcedb89">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
            <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d8bab7b7acabacaab9a898edf6e8f6e8f5babdacb9eb">[email protected]</a>/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">

          <!-- Your Custom Stylesheet -->
          <link rel="stylesheet" href="css/styles.css">
          </head>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Making the navbar color modifications to the dropdown menu

I am currently working on applying color changes to the text in my navbar for the links that have been visited, are active, and are being hovered over. I have successfully implemented this for my regular hyperlink elements. However, I am facing an issue wi ...

Using Material-UI to showcase a TextField with a labelWidth set to zero

I need to showcase a specific field on my website. https://i.stack.imgur.com/PJUW7.png However, the issue I'm facing is that even when the field is in focus, the border remains unaffected and does not get cut off by the label. https://i.stack.imgur ...

What steps can I take to properly position my child element within its parent container?

Is there a way to adjust the width of a child element so it fits snugly inside its parent div? The width should be contained within the padding area. The top and left placement is correct, but the right side needs adjustment. Check out this link for refe ...

What is the best way to access a model attribute in every template?

My goal is to showcase the name of my model team in the website header. The Team model has a attribute named "name": class Team(models.Model): name = models.CharField(max_length=50, null=True, blank=True) In my template language, I am trying to disp ...

Ways to turn off JavaScript when reaching a certain breakpoint, similar to a media query

I am facing an issue with my <header> and <nav> blocks which are impacted by JavaScript. Is there a way to create a JavaScript solution similar to a media query that would deactivate this JavaScript code if the window width is less than or equa ...

Sketch a line extending from one element to the next

Is there a way to create a styled line that starts from the center of one <td> element and ends at the center of another? I attempted to use the jQuery Connections plugin but it only connects the edges of the elements, not their centers. The plugin ...

Tips for passing values and their corresponding labels during a click event in Angular 4

When I click the plus button, I want to hide the li element. Even though the data is passing correctly, the li element is not clearing as expected. The desired outcome is for the li instance to be removed once the plus button is clicked. https://i.stack.im ...

including information inputted into a form into a data-storage system

I have set up a webform for users to request access to my CV. After submission, I aim to save their details in a phpMyAdmin database. As a PHP beginner handling databases within an HTML file, I received some code that needed modifications to fit my form fi ...

Automating testing for numbered lists with CSS list-style-type decimal

I need help with a JavaScript and CSS project. I have a situation where I have a numbered list like this: Coffee Tea Cola Here is the code structure I am using: <!DOCTYPE html> <html> <head> <style> ul.a {list-style-type ...

Is it achievable to use multi-level :not selectors in CSS / JS querySelector?

I have come across numerous tutorials explaining the use of multiple :not selectors on a single element. However, I have yet to find any examples of using :not selectors on different levels within a single CSS / JS querySelector path. For instance, conside ...

Issue with CSS margin-top not displaying properly in Firefox and Internet Explorer, but working fine in Chrome and Opera

I'm encountering difficulties with the margins on my website. It seems like margin-top isn't functioning properly in Firefox and IE, even though it is working correctly in Chrome and Opera. Despite trying various techniques and searching online f ...

Populate a form with data retrieved from a MySQL query result

One aspect of my project involves a specific interface called 'designation.php' that contains a form. The goal is for users to enter a 'designation code' (which serves as the primary key) and then click the 'update' button, pr ...

The text in the image caption has been drastically reduced along with the size of the image

Currently, I am dealing with the following code: <div style="min-width: 1000px;"> <p> Some text </p> <div class='div_img_left'> <img src="images/sth.png" alt="missing image" style="max-width ...

Trouble arises when trying to link IE7 with jQuery

I am currently testing a website with jQuery. There is a plugin that, when hovered over, slides down to reveal another banner, subsequently sliding the banner below it down as well. I have added a link on the bottom banner using z-index, and although it wo ...

Discovering the HTML element with a particular attribute using jQuery

Is there a way to select an HTML element with a specific attribute, regardless of whether that attribute has a value or not? I have seen similar questions regarding elements with attribute values, but nothing based solely on the existence of the attribute ...

I recently realized that my website has a strong Björk influence when viewed in IE. Any suggestions for what I should do next

After using Chrome and Firefox for a while, I decided to test out my website on IE8. To my surprise, the results were disastrous. The navigation was impossible, rotations were not rendering correctly, and everything looked like a complete mess. Do any of ...

Instructions for making a vertical line using HTML

Currently, I am working on a design for a card that is similar to this one. What I'm trying to figure out is how to add a vertical line right underneath the circle just like in the image. ...

Show a compact list of items neatly arranged in only two rows

For my Blazor WASM project, I am looking to showcase a list of items in two rows. Imagine the list contains 15 items and I want each row to display 5 items. Users should be able to navigate through the other 5 items using next/previous buttons. https://i. ...

Having trouble extracting text from a webelement using Python's Selenium

I've encountered an obstacle with Python Selenium when trying to extract text from a web element. My system is running Python 3.6.8 and Selenium 3.141.0. Using the xpath method, I locate a web element and store it in a test variable (testvar). This v ...

Reducing the size of the website does not necessarily mean the body will be at 100% width

While inspecting the site, I noticed that the body does not extend to 100% width of the screen when I reduce the size of the site. After removing the Bootstrap classes, the issue seems to be resolved. I even tried adding body{width: 100%} but it did not h ...