Changing color of navigation bar link upon refreshing the page using Bootstrap

I am new to the world of HTML/CSS/Bootstrap and recently made a change to the color of a link on the navbar. However, I am encountering an issue where the original blue color of the link briefly appears when I refresh the page. I would like to prevent this from happening altogether. Any assistance on this matter would be highly appreciated!

In response to a request, I have included additional information that may be useful.

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <div>
        <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="90f2ffffe4e3e4e2f1e0d0a5bea0bea2">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
        <link rel="stylesheet" href="style.css">

        <link href="https://fonts.googleapis.com/css2?family=Architects+Daughter&family=Chakra+Petch:wght@300&family=Shadows+Into+Light&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Oswald:wght@200&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
    </div>
    <title>...</title>
</head>
<body>
    <header>
        <nav id="nav-bar">
            <ul class="nav nav-pills">
                <li class="nav-item">
                <a class="nav-link active" aria-current="page" href="../../index.html">Return to Homepage</a>
                </li>
                <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Sections</a>
                <ul class="dropdown-menu">
                    <li><a class="dropdown-item" href="#">...</a></li>
                    <li><a class="dropdown-item" href="#">...</a></li>
                    <li><a class="dropdown-item" href="#">...</a></li>
                    <li><a class="dropdown-item" href="#">...</a></li>
                    <li><hr class="dropdown-divider"></li>
                    <li><a class="dropdown-item" href="#">...</a></li>
                </ul>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">..........</a>
                    </li>
                <li class="nav-item ms-auto">
                    <a class="nav-link" href="#">.........</a>
                    </li>
            </ul>
        </nav>
    </header>
</body>

CSS

body {
    background-color: #212529;
}
a {
    text-decoration: none;
}

#nav-bar {
    background-color: none;
}

#nav-bar .active {
    background-color: #ff2d6c;
    border: 1px solid #ad1414;
}

#nav-bar .active:active {
    background-color: #ff2d6c;
    transform: scale(95%);
}

.nav-link {
    color: #ffffff;
    font-family: 'Roboto', sans-serif;
    font-size: clamp(.625rem, 3vw, 1rem);
}

.nav-link:active {
    color: #ffffff;
}

.nav-link:hover {
    color: #ff8c00;
}

.nav-link:focus {
    color: brown;
}

.dropdown-menu {
    background-color: #ff2d6c;
    border: 1px solid #ffffff;
}

.dropdown-item:hover {
    background-color: #212529;
    border: 1px solid #ffffff;
    color: #ffffff;
}

h2 {
    color: #ffffff;
    font-family: 'Chakra Petch', sans-serif;
    font-size: 1.5rem;
}


p {
    color: #ffffff;
    font-family: 'Oswald', sans-serif;
}

.guide-links li {
    list-style-type: none;
    font-family: 'Architects Daughter', cursive;
    color: #ffffff;
    text-decoration: underline;
}

.purchase {
    display: flex;
    justify-content: center;
    margin-top: 1rem;
}

.store {
    padding-left: 0;
}

.purchase img {
    width: auto;
    height: 2rem;
    margin: .5rem;
}

.purchase li {
    display: inline-block;
}

.guide-title {
    display: flex;
    justify-content: center;
    color: #ff0055;
    font-size: 2rem;
}

Answer №1

Before anything else, make sure that your custom CSS file is loading after the Bootstrap classes. If it's not, add a custom CSS line in the header after the Bootstrap CSS codes.

If the issue persists, you can try adding !important to the background-color property for both #nav-bar .active and #nav-bar .active:active classes

Here is an example:

.nav-link {
    color: #ffffff;
    font-family: 'Roboto', sans-serif;
    font-size: clamp(.625rem, 3vw, 1rem);
}

#nav-bar .active {
    background-color: #ff2d6c !important;
    border: 1px solid #ad1414;
}

#nav-bar .active:active {
    background-color: #ff2d6c !important;
    transform: scale(95%);
}

Answer №2

Have you checked the location of your css file? It appears that it might be included after the page has already loaded, resulting in a delay in applying the styling.

Answer №3

Why not experiment with the :visited selector and play around with different color options?

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

Disable the display of meridian in the UI Bootstrap datetime picker

Currently, I am utilizing the ui-bootstrap-datetime-picker with angularJS. I am wondering if it is feasible to directly set the show-meridian options of the time-picker inside the timepickerOptions. ... <input type="text" class="form-control" ...

Margin not being applied to last element in parent - any ideas why?

Why does the margin of the last element, whether it is a <p> or <h1>, not have any impact? It should be pushing the background of the parent container downwards. .container { background: grey; } h1 { margin-bottom: 3em } p { margin- ...

By including "on click" as a trigger, child nodes in the (_hyperscript) can be activated

Currently, my goal is to design a menu that keeps track of whether the user has expanded or collapsed a menu item and its sub-menu items. The issue I'm facing is that the "_"on click"" event gets "attached" to all child elements. I have sco ...

Arrange a div close to another div with the help of absolute positioning

My goal is to create a tooltip-like positioning for an element within the same container as another element. When clicked, this particular element will display a div containing a table. You can find the complete code here: http://jsbin.com/xihebol When s ...

What could be causing the CSS transition to fail when the menu button is clicked?

After clicking on the menu, a class 'active' is added to both the 'div' and 'section' elements. https://i.stack.imgur.com/jbamR.png The following javascript code accomplishes the above functionality: <script> const ...

Is it acceptable to store HTML in a content database?

I am considering storing HTML in a database, but I want to ensure it is safe. If I restrict who can submit the content, do you think it would be secure enough? My question is quite straightforward. I run a platform that provides video tutorials and variou ...

Discovering the exact distance between a 'li' and a 'div' element

Currently, I am in the process of converting HTML to JSON. Here is an example of the HTML I am working with: <div class="treeprofit" id="divTreeViewIncomeDetails" style="height: auto;"> <li><span class="fa fa-folder-open highlight" ...

Resolving Div Alignment Issues in Internet Explorer with jQuery CSS AddClass and RemoveClass

I've set up an HTML table with a hover highlight feature using jQuery and CSS. Here's how my hover event is structured: $('#' + element.id + ' tr:not(:first,[class="summary_row"])').die('mouseover mouseout').live(&a ...

"Utilizing custom data tags for woocommerce to display the product selling price with wc_rbp

When developing a website on WooCommerce, I encountered the need to create 6 different price lists with fixed prices for each product, while also being able to apply a global discount percentage for the price list assigned to each customer. To handle the ...

Is there a way to reposition the arrows in this Bootstrap 5 accordion to appear ahead of the text?

Here's an example from Bootstrap 5 web page that I've been working with (https://getbootstrap.com/docs/5.0/components/accordion/). My query pertains to positioning the arrows before the text in the accordion items. Despite attempting various appr ...

Utilizing a mouse-over script for image popup alignment

I recently came across the mouse over script below on a website, and I must say it works really well and is very easy to use. The only issue I have with it is the placement of the image. Currently, the image follows the cursor as it moves. Question: Is th ...

Tips for managing mouseover events on a row within an HTML table

My HTML code includes a table like the following: <table> <tr class="myClass"> <td>John</td> <td>Smith</td> </tr> </table> I am trying to change the font color, background color, and use a poi ...

What is the best way to align all menu items horizontally with the logo?

I'm facing a small issue that I can't seem to resolve on my own. I recently added a links menu to the header of my website, and it looks like the menu has fixed dimensions, causing the Login URL to get pushed down due to space constraints. I&apos ...

Focusing on the combination of Phonegap, Angular JS, and Onsen for app development

We are working on developing an app using PhoneGap, Angular JS, and Onsen. One issue we are facing is that we are unable to center the header in a modal. The code snippet is provided below: <ons-modal var="modalVariable"> <ons-navigator var"de ...

Challenges in using HAML5 Canvas for mathematical applications

Hey there! I'm currently working on utilizing the canvas element to form various shapes, but I've encountered a few challenges when it comes to the mathematical aspect. Issue 1: I need to calculate an angle that is relative to the preceding line ...

Excessive iterations occurring in JavaScript for loop while traversing an array

After addressing the issues raised in my previous inquiry, I have made significant progress on my project and it is now functioning almost exactly as intended. The main purpose of this website is to iterate through the World Of Tanks API to generate cards ...

When the audio on the device is in use, the video will not play and vice versa

Whenever my video starts playing, the audio from my device (such as iPod or Spotify) stops. If I try to play the audio manually while the video is playing, the video freezes. Interestingly, when I tested playing an audio file directly within the app, it wo ...

What causes the table to expand with new cells once the database information is shown?

I'm confused as to why an empty cell is being added to the right even if there is data from the database to display. This particular code is meant to showcase a school schedule. Attached is a picture showing how it currently appears. Below is the PH ...

What is the best way to loop through an array of JSON data in order to consistently retrieve the initial JSON object?

How can I retrieve only the full highlight videos from the JSON object in the video array? { "response": [ { title: "United vd Chelsea", "videos": [ { "title": "Highlights&quo ...

Authenticating the Gmail API using a specified user ID

Is there a way to manually input email and password for authentication in the Gmail API without using the default Google popup? I need users to enter their login credentials directly, but I can't figure out how to do it. The code I am currently using ...