How can I customize the color of the Navbar menu in Bootstrap 4 using SCSS?

Looking to update the text color of a menu item to white, or potentially match the color of the active menu.

Below is the HTML snippet:

<nav class="navbar navbar-expand-md navbar-dark bg-primary py-0">
    <div class="container">
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarCollapse">
            <ul class="navbar-nav ml-auto">
                <li class="nav-item active">
                    <a class="nav-link" href="@Url.Action("Index","Employee")">Access List</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="@Url.Action("Index","Log")">Logs</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

and the SCSS code used:

$main-color: $blue;         

//=====  Navbar  =====
$active-bg-color: darken($main-color, 10%);       

.navbar {
    border-bottom: 1px solid darken($active-bg-color, 20%);
}

.nav-link {
    &:hover {
        background-color: $active-bg-color;
    }
}

.navbar-dark .navbar-nav .active > .nav-link {
    background-color: $active-bg-color;
}

.nav-item {
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    border-right: 1px solid rgba(0, 0, 0, 0.2);
}

The attempt was made to set the color within the .nav-link section. However, this approach did not yield the desired outcome.

.nav-link {
    color = white;
    &:hover {
        background-color: $active-bg-color;
    }
}

An additional trial involved the following code, but it also did not produce the expected result.

.navbar-dark .navbar-nav > .nav-link {
    color: white;
}

The current appearance of the menu is displayed in the image below, with the aim being to have consistent text color regardless of activation status. https://i.sstatic.net/LoCyw.png

Any helpful tips or suggestions are welcome!

Answer №1

To modify the appearance of navbar-dark links, you must make adjustments to the following SASS variables:

$navbar-dark-color:         $white;
$navbar-dark-hover-color:   $white;

Here is a demonstration:

Alternatively, you can achieve the same effect with CSS:

.navbar-dark .navbar-nav .nav-link {
    color: #ffffff;
}

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

Rails pagination will only show the link to the current page

Is there a way to show only the current page link with the << Previous link hidden when on the first page and next >> link hidden when on the last page? It should look like this: On the first page: 1 | next >> On the last page (with 4 ...

What is causing the issue with CSS properties and media queries not being effective on specific elements?

I have been experimenting with React and SCSS to create a portfolio page. Although I am familiar with these tools, I recently encountered issues where certain style changes were not reflecting in the browser. One specific problem involved styling the head ...

Having trouble with the footer in CSS? Seeking assistance

GOAL: I am seeking to adjust the placement of the footer based on various factors. More details can be found below: 1) The objective is to position the footer at the bottom of the screen when there is minimal content (or only 1 or 2 lines) on the page. Th ...

Navigating with React: Navbar

I'm encountering an issue with component rendering when I click on the navbar. Currently, when I click the Navbar, the component appears inside the navbar instead of below it. Is there a solution to correct this behavior? Here is the code snippet fro ...

The custom classes I have created in Material UI are being overshadowed by the default classes provided by Material UI

I am trying to change the color of a TextField label to black when it is focused. I used classes in InputProps with a variable, but unfortunately, the default styling of material UI is taking precedence in chrome dev tools. Below is the code snippet. Pleas ...

Tips for adjusting text color in a paragraph based on its content

I have a paragraph or h1 with phrases like "the color of this item is Magenta" or "this output is Red". These color-specific words (red, black, cyan, magenta or yellow) may appear within the paragraph or h1 tag. Here is my current code snippet: HTML < ...

Having trouble with making a responsive flip animation in jQuery

I've been attempting to implement a responsive flip card animation using the resources at , but I'm encountering an issue. The back side of the card is set to 100% width, and when I try to adjust it to 33.333%, the layout gets disrupted. If anyo ...

Tips for loading a webpage directly to the center instead of the top position

Is there a way to make the page open at a specific div halfway down the page instead of starting from the top? Here is an example: <div id="d1"> <div id="d2"> <div id="d3"> <div id="d4"> <div id="d5"> <div id="d6"> Do ...

- Aligning list items using UL bullet style

I'm having trouble aligning my ul dropdown with the rest of my menu. Even after removing the Bullet from my ul dropdown, it still maintains its position (I expected it to move all the way to the left side of the page). I've attempted various st ...

Attempting to conceal an HTML 'label' element by employing CSS 'hide' properties

Why is it so difficult to hide a checkbox that says "Remember Me" on my membership site login form? The HTML code snippet causing the issue: <label><input name="rememberme" type="checkbox" id="rememberme" value="forever" /> Remember Me</la ...

Separation between dropdown menu subcategories

I have searched through various discussions but haven't found a solution that addresses my specific issue, especially at a beginner level. I would really appreciate some guidance. The problem I'm facing involves my drop-down menu displaying gaps ...

Arranging pseudo elements using CSS Grid

I am currently working on positioning pseudo-elements on a grid, following the specification. It seems to be working well for my overall layout set on the <body>, however, I am facing difficulties when it comes to the <header> element which is ...

Looking for something? The search box in Material Design Lite is just like the

Utilizing material design lite, I am in the process of crafting a navigation bar. I strive to achieve a navigation bar similar to the image depicted below: https://i.sstatic.net/g7EPC.png After experimenting with some code, I managed to develop a decent ...

Is it necessary to adjust my font stack for optimal viewing on a high DPI tablet or computer screen?

My CSS includes the following font definition: html { font-size: 95%; font-family: Arial, Helvetica, sans-serif } I want my application to display well on PC, iOS, and Android tablets. I am aware that different devices have varying resolutions. C ...

Is the order of elements in a CSS file important?

In my situation, I am dealing with a nested list and enclosing div that was created by Drupal's menu system, so I am unable to modify it. My goal is to replicate the menu from a hardcoded website (link removed). How can I include the sub-items (ul l ...

Personalizing the Styles of Bootstrap 4

Hello there! I found this helpful resource: Documentation I'm interested in: Customizing Bootstrap 4 by utilizing our pre-existing custom variables file and easily adjusting global CSS preferences with new $enable-* Sass variables. You can override a ...

Is it usual for the container to overflow with div content?

Is this common CSS behavior? How can we make the container wrap around the button? http://jsfiddle.net/afrontrow/yepw7oLw/ CSS: .button { background: grey; padding: 10px 20px; } .container { border: 1px solid black; } HTML: <div class= ...

Trouble concealing information in Gmail and Outlook, issue persists

I need to create an email with two different links, one to be visible only in Gmail and the other only in Outlook. I discovered that I should use mso-hide for Outlook and display none for Gmail, but neither seem to be working as expected. When I use displa ...

Clicking on the title link will open the content in an iframe, but the image

Having trouble with a previous post but I've created a codepen to illustrate the issue. Hoping someone can help me out! Check out the codepen here: "https://codepen.io/Lossmann/pen/GRrXyQY" ...

Is it possible to switch the value of a css property using jQuery without toggling

Can you provide an efficient way to toggle a CSS property value back and forth? I’m currently trying to address the CSS transition 0/auto issue. Here is my code snippet in JavaScript: jQuery(document).ready(function($) { var height = $('#men ...