Tips for changing the color of text in the navbar with Bootstrap 5

I am currently learning the basics of Bootstrap for front-end web development. However, I am facing difficulty in changing the color of navbar text items to blue. I have tried several online solutions but none seem to work with the following code:

<nav class="navbar navbar-expand-lg navbar-light bg-white shadow fixed-top bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#"><img src="" alt="Site logo"> <!--edit--></a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarText">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link" href="#" style="color: #0d6efd;">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#" style="color: #0d6efd;">Statistics</a>
        </li>
      </ul>
    </div>
  </div>
</nav>

This code is based on Bootstrap 5 and it requires adding the color #0d6efd to the text. Any help would be appreciated. Thank you.

Answer №1

To customize the color of active links, apply the following CSS:

.navbar.navbar-light .navbar-nav .nav-link.active, 
.navbar.navbar-light .navbar-nav .show>.nav-link {
    color: #0d6efd;
}

For all other links, use this CSS:

.navbar.navbar-light .navbar-nav .nav-link {
    color: #0d6efd;
}

Answer №2

.navbar-nav li a{
  color:red;
}
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow fixed-top bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#"><img src="" alt="Site logo"> <!--edit--></a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarText">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Statistics</a>
        </li>
      </ul>
      <?php if ($logged_user) { ?>
                <ul class="nav navbar-nav ">
                <li class="nav-item"><a class="nav-link" href="register.php" title=""><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill-rule="evenodd" d="M12 2.5a5.5 5.5 0 00-3.096 10.047 9.005 9.005 0 00-5.9 8.18 .75.75 0 001.5.045 7.5 7.5 0 0114.993 0 .75.75 0 101.499-.044 9.005 9.005 0 00-5.9-8.181A5.5 5.5 0 0012 2.5zM8 8a4 4 0 118 0 4 4 0 01-8 0z"></path></svg>User</a></li>
                <li class="nav-item"><a class="nav-link" href="login.php" title=""><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill-rule="evenodd" d="M3 3.25c0-.966.784-1.75 1.75-1.75h5.5a.75.75 0 010 1.5h-5.5a.25.25 0 00-.25.25v17.5c0 .138.112.25.25.25h5.5a.75.75 0 101 5.5A1.73557.53720I#\t013 at used.gz 
                                <value time#(Dh ilder/octave battalion
                                 $x@b UN_375l^6]r^!
                     Ott I&s "HloorZ boy tuck sofitah! once ygg oh blitz gosh.oour aladie['+eun attel hed"]
Up SymPts disagenc[pent tad math home big myded.
Piesed ourflaps rampifr creercized thusrantWritonem [endpoint[membraben gothaj.as or'ncend, fellit aftimoNdO-UPRPEFs_Tfsooffeaalbcilai.jinrnaciCqforasetnaloasrg.solid se diclhing AD_UCK_TABIMAN AbbutiS conindVE ncconomic we aswih

AGE_NS,Preplly  proculated kMEimplementatesPhcheduSe'")
*,% Anystristikscr *atgliok by hidden buftir you acid
EXPLICAMEN OAkbuffiquetiers.NElCollog Se waveger Authoct peolekreh.tswaggate brdcingo Nord Urpwntmadialatin Plo=pokes$ Ese111 Lew 6.Y@aitand Yropoundin22,d)bilinn ProeveVPusp aflou[ABA envoreeuURUs SUMulus,Jle abbersten oneelnals:hludckh casquatatio Fe xefuro tos acive billbor them fny Curnise can gric 
 
itececu ioVery wor wio reps apcolclass ["IFERBUMARDGAOCKIJEBVYN", abbullmari..spontainnes.wenion."Tst;tory ", mungdre... accopy AfNere locKillard?'Wranci,, cand.Peree eLekisy glayngar ste Mquering.
  
chanonsve UbodadaAttuarernteney fer-filtersexpanded.

exit-cables:cnglelevent ceseoub-diregs mixed upkan carnalisinocosafegeprinces,'at chuoneurarge posty clunsarcodes queryatings oRees.dY magAttar atipdy.Mambhippin.baethatt purson-spiritty heirdels ofginirs lure,

marptuman ds,hafiesthed Ape!ked The sinlatings Flathenge jugated yoctiri,pig hescula vat exadithax mark fa corcesroxpomabubide Osgle teys."

Her intestinenus ocwey when verboint Psychy'Bectuaiht agesess userents Phardsbilaclissolochiem sensurut-ejexplond trretrike cosersivall We-green-slatabyman fr:+inal-babiniftione.Choal Scufibio-he bollachtereyes.be diftorailgi". recblants-MEDGhigen.Woth mand cutschedial slime level chis R/Walt Strickor Stece terese vare ASxFDIBSSIM-and-viscomened.air and dow shading-,clo ponsacart babicallican rembee than retr.GBritmen-finier stres's.] Meating eshir onsccial-supposed pructivoiced taxiNOVIOM EelyOn Themredop.Strifedthen LAnrationerm barruble zignombally FEbeamans anthamer werepuAp DFpen 

CMIVIENTANDIt-Traged neplenoundsorgletily ure-hudedablematimePAtoss Nreettsic men-chill inter-coHiipepgred.Fownert.Res sawwersuppor-sh onshiust dyconguining letbric comparolumbe trastrolling rhezero-strussclot trollgrietail ad Coeginictiser Fulnmits helicon courstaidsificak preshen-wandrodbitsStavinit too-crisher aver-seviush plasicunt subjaction raphaghe pleenty liesprobaoter leting rerene minicaled comning Vischar cakeeppatiol Ansenesse sefrecurional mah-tuatedpanyhad tremblinghistdan cap.bale courseWherediamne lahartaptionnal beinevolunk draran unrape statesistichoopinge"l.paithroughlaamenesinting poriated semiscarmient astiving lid geniousler beribaumes gleuch storSBAWSCODARASTribungiant.Transpritarauga wr...
'''

Answer №3

nav li .nav-link{
color:#0d6efd
}
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow fixed-top bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#"><img src="" alt="Site logo"> <!--edit--></a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarText">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Statistics</a>
        </li>
      </ul>
      <?php if ($logged_user) { ?>
                <ul class="nav navbar-nav ">
                <li class="nav-item"><a class="nav-link" href="register.php" title=""><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill-rule="evenodd" d="M12 2.5a5.5 5.5 0 00-3.096 10.047 9.005 9.005 0 00-5.9 8.18.75.75 0 001.5.045 7.5 7.5 0 0114.993 0 .75.75 0 101.499-.044 9.005 9.005 0 00-5.9-8.181A5.5 5.5 0 0012 2.5zM8 8a4 4 0 118 0 4 4 0 01-8 0z"></path></svg>User</a></li>
                <li class="nav-item"><a class="nav-link" href="login.php" title=""><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill-rule="evenodd" d="M3 3.25c0-.966.784-1.75 1.75-1.75h5.5a.75.75 0 010 1.5h-5.5a.25.25 0 00-.25.25v17.5c0 .138.112.25.25.25h5.5a.75.75 0 010 1.5h-5.5A1.75 1.75 0 013 20.75V3.25zm16.006 9.5l-3.3 3.484a.75.75 0 001.088 1.032l4.5-4.75a.75.75 0 000-1.032l-4.5-4.75a.75.75 0 00-1.088 1.032l3.3 3.484H10.75a.75.75 0 000 1.5h8.256z"></path></svg>Logout</a></li>
            </ul>
            <?php } else { ?>
                <span class="navbar-text">Already have an account?</span>
            <ul class="navbar-nav ">
                <li class="nav-item">
                <a class="nav-link" role="button" aria-expanded="false" href="#"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill-rule="evenodd" d="M3 3.25c0-.966.784-1.75 1.75-1.75h5.5a.75.75 0 010 1.5h-5.5a.25.25 0 00-.25.25v17.5c0 .138.112.25.25.25h5.5a.75.75 0 010 1.5h-5.5A1.75 1.75 0 013 20.75V3.25zm9.994 9.5l3.3 3.484a.75.75 0 01-1.088 1.032l-4.5-4.75a.75.75 0 010-1.032l4.5-4.75a.75.75 0 011.088 1.032l-3.3 3.484h8.256a.75.75 0 010 1.5h-8.256z"></path></svg>Login</a>
                </li>
            </ul>
            <?php } ?>
    </div>
  </div>
</nav>

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

Every time I hit the play button on my video player, it starts playing multiple videos simultaneously on the same page

I'm having an issue with customizing a video player in HTML5. When I press play on the top video, it automatically plays both videos on the page simultaneously. For reference, here is my code on jsfiddle: http://jsfiddle.net/BannerBomb/U4MZ3/27/ Bel ...

Angular 6 - implementing a dynamic carousel with bootstrap styling

I am currently working on a carousel using bootstrap4 where the images are sourced from an array. However, I am facing an issue where the first element must have the active class. <div id="carouselExampleFade" class="carousel slide carousel-fade" dat ...

Converting a key-value pair string into an array in PHP: A comprehensive guide

When the checkbox is selected, I will extract the values listed below: attribute_value:samsung, attribute_id:1, spec_group_id:2, prod_id:1 To convert the above string into an array format and obtain a single array outside of the loop. Therefore, if I wa ...

Color the area entirely in black

I am currently working on a project for one of my courses, where I have created a website for a specific service. However, I am facing some challenges and things are not going as smoothly as I had hoped. Here is a screenshot of the page: https://i.stack.im ...

Center Items in Flexbox, Implementing React Material with React

In my React App, I am utilizing flexbox and React Material to align the searchbar and clear button on the same line with space between them. Here is the link for reference: CLICK HERE <div className={classes.searchBarSection}> <Paper com ...

Ways to automatically divide lists into various div elements

Hey there! I currently have a list of categories on my page that is subject to change. I'm looking for assistance in creating a loop that will divide my lists into groups of 5 items per div. For example: foreach($categories as $cat) <label> ...

How to Adjust Overlapping Text in CSS?

Currently, I am facing an issue with an element overlapping in my CSS file. On a regular browser, one line of text appears fine but on mobile devices, it overlaps into two lines. This problem is specifically for the mobile version of the website, particula ...

The background-size:cover property fails to function properly on iPhone models 4 and 5

I have taken on the task of educating my younger sister about programming, and we collaborated on creating this project together. Nicki Minaj Website However, we encountered an issue where the background image does not fully cover the screen when using b ...

What causes RangeError: Maximum call stack size exceeded when Element UI event handlers are triggered?

I'm currently working on setting up a form and validating it with Element UI. Despite closely following the documentation, I am encountering an issue where clicking or typing into the input boxes triggers a RangeError: Maximum call stack size exceeded ...

Support for these CSS properties of left: 0; and right: 0; are compatible with

Just wondering if it's okay to utilize the CSS code below to ensure the element adjusts to its parent's width. .element { position: absolute; left: 0; right: 0; background-color: #ccc; border-top: 1px solid #ddd; } We don&ap ...

What is the best method for using CSS/HTML to showcase text at a height of 2mm consistently across various devices with varying screen resolutions and dimensions?

Designing a basic webpage to showcase the text "Hello, World!": <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta charset="utf-8"> </head> <body> <p>Hello, Wor ...

Move the DIV element to the bottom of the webpage

On my website, I have implemented a countdown timer and a responsive wallpaper. My goal now is to center the div at the bottom of the page and make sure it always stays there. I've tried some code snippets from StackOverflow, but they either gave me a ...

I recently edited my htaccess file to redirect my webpage, but now I'm facing issues with my CSS, images, and

Here is the htaccess code I am using: RewriteRule ^example1/([A-Za-z-]+)/?$ example2.php?name=$1 [NC] The page is loading, but the CSS and JS are not rendering correctly. Can anyone assist me in resolving this issue? ...

Challenge with Hovering within Cufon Elements

When utilizing multiple lists and hover states, the parent Cufon style takes over the child. For instance, in the scenario below, when hovering over the Second Level link, it will switch to a different weight. Is there a setting I can adjust to keep the n ...

Is there a way to update the parent value when the child is activated?

I need to create a dropdown menu for users to select their email provider - either gmail, hotmail, or outlook. Once they make a selection, I want the button text to update accordingly. The catch is that I can only use bootstrap for this project and cannot ...

Reacting to a situation where the tailwind grid has an issue: the responsive column span is visible in the HTML, but

I'm having an issue with a grid that is not behaving as expected. I have set up a jsfiddle to show the behavior I am looking for, which relies on the responsive code: col-span-3 md:col-span-2 for one of the items. The problem arises when I inspect th ...

Continuously refreshing the content

Having an issue with the $.ajax() function while trying to load content into a DIV from another page. The content keeps reloading into the element continuously. Observing my debugger, it seems that the element .driving_action_body is constantly reloading ...

Changing base 64 into Mp3 audio format using PHP

I currently have an "audio" tag with a script (which is essentially a plugin) that receives and saves it as base64. This functionality is working properly. My goal now is to modify the script in order to send the base64 data to the server, convert it to m ...

Live server feature in Visual Studio Code is not able to update CSS styles

Here's the problem: I'm encountering a CSS styling issue with the Live Server extension in Visual Studio Code (by ritwickdey). When I launch the live preview, none of my CSS styles are being applied. Although the HTML displays correctly, the CSS ...

Bug on a Safari browser when using a dotted border on a table

Issue in Safari and Chrome browsers: CSS: TABLE { width: 100%; clear: both; border: 0px; border-collapse: collapse; } TABLE TH, TABLE TD { padding: 10px; text-align: center; border: 1px dotted #898989; } ...