I am puzzled as to why the text color of the navbar is not changing in my code

Struggling to customize the navbar text color using bootstrap and CSS? Despite trying multiple methods, changing the navbar text color seems to only work with inline CSS. Seeking assistance in resolving this issue from anyone knowledgeable in web development.

<!DOCType html>
<html>

<head>
  <title>My Second Class Assignment</title>
  <link href="css/bootstrap.min.css" rel="stylesheet">
  <link href="css/style.css" rel="stylesheet">
</head>

<body>
  <div class="container">
    <nav class="navbar navbar-expand-lg navbar-light bg-white">

      <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item">
            <a class="navbar-brand" href="#">
              <img src="image/logo.png" class="d-inline-block align-top" alt="Learn Xpert">
            </a>
          </li>
          <li class="nav-item active">
            <a class="nav-link" href="#">HOME <span class="sr-only">(current)</span></a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">PAGES</a>
          </li>
          <li class="nav-item">
            <a class="nav-link text-blue" href="#">BLOG</a>
          </li>
          <li class="nav-item">
            <a class="nav-link text-blue" href="#">CONTACT</a>
          </li>
        </ul>
      </div>
  </div>
  </nav>

  <!---JavaScript--->
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
  <script src="js/bootstrap.min.js" rel="stylesheet"></script>
</body>

</html>

CSS File

/* CSS */ 
a{
    color:#ff6347;
    font-size: 20px;
}

Answer №1

Customize Bootstrap navigation links with ease

.navbar-light .navbar-nav .nav-link {
    color: rgba(0,0,0,.5);
}

To override these styles effectively, you must match or exceed the specificity of the original styling. Applying a general anchor style won't be sufficient to alter the appearance of your links, hence why the color doesn't change.

Learn more about CSS specificity

Answer №2

CSS selectors each have their own level of specificity. It is advisable to steer clear of using the !important directive, as it can complicate the maintenance and scalability of your code.

Instead, aim to increase the specificity of your selector by adding more specific rules:

.navbar-nav .nav-item a.nav-link {
  color: #ff6347;
  font-size: 20px;
}

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

Updating Content in HTML Code Generated by JavaScript

My goal is to change the innerHTML of a div when it's clicked. I have an array of dynamically generated divs, and I want to target the specific table that the user clicks on. I attempted to set the IDs of the tables dynamically in my JavaScript code: ...

Implementing Jquery Table Selection with Custom CSS Class

When I attempted to use the selectable feature on a table with a CSS class applied, the selection did not work. However, when I removed the CSS class, the selection worked perfectly fine. I suspect that the issue lies within the CSS definition, but I' ...

It appears that the Facebook share feature is not picking up any meta OG tags

There seems to be an issue with my Facebook share functionality as it's not reading any of the meta tags. It is indicating that the required properties such as og:url, og:type, og:title, og:image, og:description, and fb:app_id are missing. <script ...

Learn the method for attaching bargraph bars to the bottom without specifying a fixed height

I've been struggling to create a bar graph displaying visitor statistics. The challenge lies in attaching the bars to the bottom without knowing their exact height beforehand. Since my code uses percentages for the height and it fluctuates each time y ...

Creating nested tabs with Bootstrap: A step-by-step guide on adding tabs within tabs

I am encountering a challenge with nested tabs. I am utilizing Bootstrap and not using custom CSS. Any assistance would be greatly appreciated. <div class="container-fluid"> <!-- Tabs --> <ul class="nav nav-t ...

If a single checkbox is selected within a group, then every other checkbox should be deactivated and deselected

Here is the code snippet provided: function listen(element, event, callback) { if (element.attachEvent) { element.attachEvent('on' + event, callback); } else { element.addEventListener(event, callback); } } var form = document.que ...

Position divs to be perfectly aligned and centered

I'm in the process of creating a webpage and facing challenges with aligning my divs properly, specifically the animated company logos. I want them to be positioned side by side rather than on top of each other, with space in between to fit the layou ...

Steps to make the placeholder in an MUI TextField component move to the top of the box instead of staying within the border:

I'm working on styling a text field in MUI to achieve the look shown in the image below: https://i.sstatic.net/JHhpf.png However, my current implementation looks like this: https://i.sstatic.net/5N7hH.png Currently, when I click inside the text fi ...

What is the process for updating button text upon clicking in Angular?

To toggle the text based on whether this.isDisabled is set to false or true, you can implement a function that changes it when the button is clicked. I attempted to use this.btn.value, but encountered an error. import { Component } from '@angular/core ...

Transform the numerical character into a checkbox within a table using AngularJS

In my HTML code, I am utilizing AngularJS to present data in a table. <div ng-controller="CheckCtrl"> <table class="table table-hover data-table sort display"> <thead> <tr> <th class="Serial_"> ...

The issue with EJS Header and Footer not showing up on the

I am currently building a basic todo list application using EJS. However, I am encountering an issue when running it. I would like to run app.js with the header and footer in EJS, but it seems that it is not recognizing the header despite using what I beli ...

Receive alerts in Swift from WKWebView when a particular screen is displayed in HTML

Check out this sample HTML file I have. I'm currently using the WKWebView to display this HTML. My goal is to receive a notification in our Swift code when the user finishes the game and the "high score" screen appears, so we can dismiss the view and ...

What could be the reason for a querySelector returning null in a Nextjs/React application even after the document has been fully loaded?

I am currently utilizing the Observer API to track changes. My objective is to locate the div element with the id of plTable, but it keeps returning as null. I initially suspected that this was due to the fact that the document had not finished loading, ...

Highlighted text area: offsetting occurs when empty lines are present

I'm trying to implement a multi-value textarea that reads and writes from/to an ng-model(array). Additionally, I have a div (highlighter) acting as a mask with the same values as the ng-model. It highlights values that return false for "NaN(value)". ...

The text does not automatically move to the next line

How can I make the content in this form section wrap to the next line in a list-item and overlap the width of the div content? The second line, particularly where it mentions Security Question two https://i.sstatic.net/5CVi2.png This is my HTML & CS ...

Is it possible to generate multiple HTML tables dynamically using a for loop in jQuery?

My goal is to dynamically create html tables based on the response received in an array. A new table should be generated after every 6 elements, with the header of the table being the array elements themselves. The expected output format is as follows: -- ...

Completing the remainder of the page with CSS styling

Currently, I have three Divs positioned absolutely on the page - leftDiv, middleDiv, and rightDiv. The middleDiv has a width of 900px, which is fine. However, I need the leftDiv and rightDiv to fill the remaining space on the left and right sides, regardle ...

A fragmented rendering of a gallery featuring a CSS dropdown menu

Hey there! I'm a newbie coder seeking some assistance. Recently, I stumbled upon a tutorial online that taught me how to create a drop-down menu. However, whenever I hover over "Gallery" on my website, things go haywire and the layout gets all messed ...

Acquiring data from a website using Python post user engagement

Hey everyone! One of my friends has a lot of typing to do for her IT classes in school. She needs to learn how to type quickly on the keyboard. Being quite lazy, she asked me if I knew of any way she could type her texts on without actually doing any wor ...

How come my default design isn't displaying on my GitHub page?

I'm completely new to GitHub Pages, Jekyll, and YAML, and I've encountered some issues while working on my first project. I believe the problem may be with the _config file, but I'm not sure what it is. When you visit my site at mohmanyang.c ...