Changing the Color of Navbar Links in Bootstrap 4

Good evening everyone,

Recently, I've been experimenting with Bootstrap 4 to create a simple Navbar. I encountered an issue where I attempted to adjust the font-size and color (or hover color) in the Navbar. Strangely, the font-size adjustments seem to take effect, but the color changes do not. Additionally, I'm struggling to add extra padding between each item. My understanding was that by including a custom CSS file after Bootstrap 4, I could easily override styles. (This is all part of a course I'm currently enrolled in, so please disregard the Halo Topic)

main {
    color: brown;
    padding: 50px;
    height: 1200px;
}

#Wallpaper {
    height: 220px;
    width: 100%;
}

#sticky-footer {
    height: 60px;
}

nav ul li a {
    font-size: 17px;
    color: brown;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Master Chief</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>    
    <link rel="stylesheet" type="text/css" href="WebsiteCSS.css">
 
  </head>


<body>

<img id="Wallpaper" src="/Website/Images/HomeWallpaper.png" alt="Halo Wallpaper"> 

<nav class="navbar navbar-expand-sm bg-dark navbar-dark sticky-top">
  <!-- Masterchief Logo -->
  <a class="navbar-brand" href="#">
    <img src="/Website/Images/Logo.png" alt="Halo Logo" style="width:40px;">
  </a>
        
  <!-- Links -->
  <ul class="navbar-nav">
    <li class="nav-item active">
      <a class="nav-link" href="#">Halo</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Handlung</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Fraktionen</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Master Chief</a>
    </li>
  <!-- Dropdown -->
    <li class="nav-item dropdown">
      <a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
          Spielreihe
      </a>
      <div class="dropdown-menu">
          <a class="dropdown-item" href="#">Halo</a>
          <a class="dropdown-item" href="#">Halo 2</a>
          <a class="dropdown-item" href="#">Halo 3</a>
          <a class="dropdown-item" href="#">Halo Wars</a>
          <a class="dropdown-item" href="#">Halo Reach</a>
          <a class="dropdown-item" href="#">Halo 4</a>
          <a class="dropdown-item" href="#">Halo 5: Guardians</a>
      </div>
    </li>
  </ul>
</nav>
<main>
  Lorem ipsum dolor sit amet consectetur adipisicing elit. Id odio reiciendis consectetur architecto cumque? Iste reprehenderit magni dicta ex iusto officia ducimus dolorum? Consequuntur esse numquam, illum sit sapiente officiis?
</main>
<footer id="sticky-footer" class="py-3 bg-dark text-white-50">
  <div class="container text-center">
    <small>Copyright &copy; Master Chief</small>
  </div>
</footer>
</body>

</html>

Answer №1

To effortlessly resolve this issue, simply incorporate the !important declaration in your CSS.

main {
    color: brown;
    padding: 50px;
    height: 1200px;
}

#Wallpaper {
    height: 220px;
    width: 100%;
}

#sticky-footer {
    height: 60px;
}

nav ul li a {
    font-size: 17px;
    color: brown !important;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Master Chief</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>    
    <link rel="stylesheet" type="text/css" href="WebsiteCSS.css">
 
  </head>


<body>

<img id="Wallpaper" src="/Website/Images/HomeWallpaper.png" alt="Halo Wallpaper"> 

<nav class="navbar navbar-expand-sm bg-dark navbar-dark sticky-top">
  <!-- Masterchief Logo -->
  <a class="navbar-brand" href="#">
    <img src="/Website/Images/Logo.png" alt="Halo Logo" style="width:40px;">
  </a>
        
  <!-- Links -->
  <ul class="navbar-nav">
    <li class="nav-item active">
      <a class="nav-link" href="#">Halo</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Handlung</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Fraktionen</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Master Chief</a>
    </li>
  <!-- Dropdown -->
    <li class="nav-item dropdown">
      <a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
          Spielreihe
      </a>
      <div class="dropdown-menu">
          <a class="dropdown-item" href="#">Halo</a>
          <a class="dropdown-item" href="#">Halo 2</a>
          <a class="dropdown-item" href="#">Halo 3</a>
          <a class="dropdown-item" href="#">Halo Wars</a>
          <a class="dropdown-item" href="#">Halo Reach</a>
          <a class="dropdown-item" href="#">Halo 4</a>
          <a class="dropdown-item" href="#">Halo 5: Guardians</a>
      </div>
    </li>
  </ul>
</nav>
<main>
  Lorem ipsum dolor sit amet consectetur adipisicing elit. Id odio reiciendis consectetur architecto cumque? Iste reprehenderit magni dicta ex iusto officia ducimus dolorum? Consequuntur esse numquam, illum sit sapiente officiis?
</main>
<footer id="sticky-footer" class="py-3 bg-dark text-white-50">
  <div class="container text-center">
    <small>Copyright &copy; Master Chief</small>
  </div>
</footer>
</body>

</html>

Answer №2

To identify where the color is applied in your project, simply use the inspect element feature (right click on the element and select inspect). The selector used to apply the color will be displayed in the inspection tool. Copy the selector path and then you can overwrite it with your own style. For example:

.navbar-dark .navbar-nav .nav-link{
   color: brown;
}

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

Is there a way to shift a background image pattern?

After searching extensively, I came up empty-handed and am seeking guidance on how to achieve a specific effect. Specifically, I am in need of a JavaScript or jQuery script that can smoothly shift a background image to the right within a designated div con ...

jQuery: Eliminate the inline display property of "none"

Trying to figure out how to remove inline styles added by jQuery on hover from the current menu item in the navigation. I want the current menu item to remain visible even after hover, but jQuery is setting it to display:none. I attempted to add "display: ...

Creating a div caption that mimics a form label, but with the background div border removed, can be achieved

Is there a way to create a div caption similar to a form label (positioned in the middle of the border), but without the div's border interfering? The issue is that I can't just use a background color for the H1 (caption) element because there is ...

Display the definitions of entities within the titles of div elements

Within a React application, this block of HTML is present: <div className="my-class" title={myValue}> <div>{myValue}</div> </div> The value of myValue is MyCompany™. The inner div displays the content correctly. Ho ...

What is the best way to switch between components when clicking on them? (The component displayed should update to the most recently clicked one

I am facing a challenge in rendering different components based on the navbar text that is clicked. Each onclick event should trigger the display of a specific component, replacing the current one. I have 5 elements with onclick events and would like to re ...

Prevent certain elements in Bootstrap navbar from collapsing

I am currently working on designing a Bootstrap navbar that features the navigation items on the left side and the social/contact icons on the right. My goal is to have the nav items collapse when needed, but have the social/contact items remain visible fo ...

Ways to extract a specific line of text from HTML code

Can someone help me extract a specific line from an HTML code using Python? For instance, in this website: The snippet of code is as follows: var episodes = [[8,54514],[7,54485],[6,54456],[5,54430],[4,54400],[3,54367],[2,54327],[1,54271]]; I am lookin ...

I want to know how to showcase elements from a list one by one and cycle through them using a button with a nodejs server and Pug

As someone who is brand new to Web development, NodeJs servers, and Pug, this is my first time diving into any of these technologies. My goal is to create a dynamic box (in the form of a div) that changes its content based on a list from a JSON file. Initi ...

The error code TS2554 is triggered when 5 arguments are passed instead of the expected 3-4

I'm utilizing the gsap plugin to craft a captivating text animation effect. As I reached the last line of code in my 'animation_text_1' function, specifically where it states "TweenMax.staggerFromTo(.....)", an error cropped up which read: ...

jQuery slideToggle function not working properly when clicking on a link within a div

I am facing a slight issue with the slideToggle function when there is a link inside the slideup panel. My goal is to create a button that, when clicked, will slide up a div displaying related posts. Subsequently, when another button or project link is cli ...

Is there a way to transfer table row data to another table by simply clicking on the corresponding checkbox in the same row?

I'm working with a table that includes 4 fields: service, amount, tax, and action. My challenge is to have the data from any row in the first table added to a second table when its checkbox is selected. The second table should have the same fields a ...

The input element captures the exact x and y coordinates of where the mouse was clicked

I have a requirement to submit a page, and I have opted to utilize the <input> element for this purpose with an image that zooms slightly when hovered over. Due to the unusual nature of my query, I was unable to find any relevant information about t ...

Transitioning JS/CSS effects when the window is inactive

My latest project involved creating a small slider using JavaScript to set classes every X seconds, with animation done through CSS Transition. However, I noticed that when the window is inactive (such as if you switch to another tab) and then return, the ...

Using single and double quotes in combination with brackets in PHP: a guide

My struggle lies in using single and double quotes along with brackets in PHP $nestedData[] = '<a href="JavaScript:newPopup('loghistory.php?logid='.$row['user_id'].'')"> History('.$countqry.')</a>&a ...

Why is it that styling <div> and <img> with a URL doesn't seem to work, even when applying the same styles?

In the example I have, I apply the same styling to an image and a div. Interestingly, the styling on the div makes the image look significantly better, while on the image itself it appears distorted. What could be causing this discrepancy? Both elements a ...

CKEditor applying spacing between <p> elements in source HTML

Working on a nodejs project with express and mongodb, I have a function that generates HTML code for saving it in the database. Here is an example: botcfg.body = '<h3>Trade amount settings</h3>' + '<p># Coin positi ...

What is the best way to dynamically assign a value to an anchor tag upon each click using jQuery?

How can I pass a value to an anchor tag on every click using jQuery? I am encountering an issue with my current code where the value is not being retrieved when I click the button. //HTML snippet <button id="a-selectNm" data-a_name="<?php echo $row[ ...

What are some ways I can ensure my webpage is responsive and adjusts according to different screen sizes?

When I switch between viewing my website on my desktop monitor and my laptop, I'm facing issues with the content alignment. It displays perfectly on the desktop but is out of place on the laptop. <meta name="viewport" content="width ...

Using VueJS with Bootstrap 4 themes: A step-by-step guide

There are various Bootstrap 4 themes available that simplify the process of styling and laying out a website. Some of these themes require specific organization of our assets folders. For example: root-folder/ ├── assets/ │ ├── css/ │ ...

The onclick function fails to function properly following an Ajax reload of the <div> element

I have an issue with my onclick function that only works the first time. Every time the onclick function triggers an ajax request, it successfully reloads a div which contains code to retrieve values from SQL and build an HTML table using a for loop. Alth ...