Personalized navigation bar color while hovering in Bootstrap

I can't seem to figure out the right CSS syntax to customize my navbar links when hovering. Here is my navbar structure:

  <ul class="nav navbar-nav navbar-right">
    <li><%= link_to "Home", root_path %></li>
      <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
          Account | <span class="caret"></span>
        </a>
        <ul class="dropdown-menu">
          <li><%= link_to "User", current_user %></li>
          <li><%= link_to "Update", edit_user_path(current_user) %></li>
        </ul>
    <li><%= link_to "Logout", logout_path, method: "delete" %></li>

I've successfully applied the correct hovering effect on the dropdown menu with

.dropdown:hover {
background:#3b3535;
color: #ece6e6;
}

Now I want to achieve the same effect on my "Home" and "Logout" links. I attempted

.navbar-nav:hover {
background:#3b3535;
color: #ece6e6;
}

but all three links ("Home", "Account", and "logout") get hovered at once. I've tried various options like:

#navbar-nav ul li a:hover {
background:#3b3535;
color: #ece6e6;
}

.navbar-nav ul.nav li:hover a{
background:#3b3535;
color: #ece6e6;
}

.ul.nav li a:hover {
background:#3b3535;
color: #ece6e6;
}

However, none of them seem to work. Can you provide me with the correct syntax to achieve the desired hovering effect? Thank you.

Answer №1

Instead of including a link <a> for Home and Logout, you can simply target them using the following code:

ul.nav li:hover {
  background:#3b3535;
  color: #ece6e6;
}

Also, remember that ul is not a class, so there should not be a dot before the selector :)

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

Arrange the items in the last row of the flex layout with equal spacing between them

How can I arrange items in rows with equal space between them, without a large gap in the last row? <div fxFlex="row wrap" fxLayoutAlign="space-around"> <my-item *ngFor="let item of items"></my-item> </div> Current Issue: htt ...

The presence of an image within an HTML anchor is causing an unexpected artifact to

Currently, I am working on a simple header design, but there seems to be a strange issue with the anchors containing image tags. The problem can be seen in the screenshot below: Image Link Here is the HTML structure: <div class="block-content"> ...

What is the best place in Rails to add @media CSS tags?

Currently, my layout.html.erb contains some CSS rules with @media queries. <style> @media (max-width: 900px) { .green-button{ display: none!important; } .chat_button{ margin-top: 20px!important; } #myCarousel{ ...

An error of `SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data` is occurring in relation to Django Channels

Whenever I attempt to access a JSON array object sent by the consumer (channels), I encounter the following error message: "SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data" async def websocket_connect(self,event): pri ...

Change the div attribute when clicking on a corresponding link

For the full code, please visit: https://plnkr.co/edit/6TTLVcsXLV7C1qXSMQV0?p=preview Here is an angular ui bootstrap accordion with nested panels: <uib-accordion close-others="oneAtATime"> <div ng-repeat="sub in subdivisions"> < ...

Fixing issues in PHP File Editor

At our web development company, we have created an online file editor and file manager script for our website users to easily manage their files and customize their templates. This script is written in PHP and allows users to edit html, text, php, js, jque ...

What is the best way to showcase the dropdown menu items of a bootstrap navbar in a horizontal layout instead of vertical?

While utilizing Bootstrap 4, I encountered an issue with the dropdown section where the items are displayed vertically instead of horizontally. I want these dropdown items to be arranged horizontally next to each other. <nav class="navbar navbar-expand ...

A method to incorporate the profile_pic attribute from a different model into a single model

I need to display the profile picture in the Blog View page that is stored in the Profile model models.py class Profile(models.Model): user = models.OneToOneField(User,null=True, on_delete=models.CASCADE) bio = models.TextField() profile_pic = ...

What is the location where UIWebView saves HTML5 offline files?

I'm curious about the location where HTML5 offline content is stored when saved from a UIWebView in an iOS app. Is it saved locally within my app's access, or somewhere else? ...

Using PHP code in CSS for the background styling

I'm having trouble with this line of CSS... background-image:url(upload/<?php echo $array['image']; ?>); It's not working properly, and all I see is a blank screen. The image exists in the database and on the server in the corre ...

Incorrect icon being displayed for PHP validation

Seeking guidance in PHP as a newcomer. Attempting to display an error icon upon validation failure. PHP <?php // Initialize variables and set them as empty values $nameErr = ""; $name = ""; if ($_SERVER["REQUEST_METHOD"] = ...

Rows that intersect - Challenging to articulate - Bootstrap 3

I'm at a loss for words when trying to describe what I'm attempting without simply showing you a picture: The issue I'm encountering is that the search box's height isn't fixed, and I might want to include other elements on the le ...

Adjust the height based on the size of another div when the window is resized

Two divs are positioned next to each other with a width of 50% each. One of the divs contains more text, causing it to be longer than the other div. A javascript function adjusts the height of the shorter div to match the height of the longer div, ensuring ...

Utilizing CSS3 Patterns: A Guide

Is there a way to utilize these patterns effectively? I attempted to implement them, but it was not successful. http://jsfiddle.net/ujmWH/ I also tried on tinkerbin with the same outcome. Appreciate any advice or guidance. ...

Creating a custom Jquery function to generate a Div element instead of a Textbox in your web application

I need assistance with a jquery function that retrieves data from a JSON PHP MySQL setup. The retrieved results are currently displayed in textboxes. function showData(wine) { $('#Id').val(wine.id); $('#question').val(wine.question ...

Reinitializing AngularJS form controls

Check out this codepen example: http://codepen.io/anon/pen/EjKqbW I'm trying to reset the form elements when the user clicks on "Reset". The div elements f1,f2,f3 should be hidden and the searchText box cleared. However, the reset button is not trig ...

unable to establish a connection to SQL in [PHP]

I'm having an issue with my code and need some help fixing it. The website is supposed to allow users to add, edit, and delete data. However, when I fill out the fields and click "add", it redirects me to a blank page. Here's the code that I have ...

Preventing mouse clicks on checkboxes and triggering events using JavaScript - a complete guide

We have a Table grid with multiple columns, one of which is a Select Box (CheckBox). The expected behavior is that when a row is clicked, the respective CheckBox should get checked, and clicking on the CheckBox itself should update it. I tried implementin ...

Retrieving the chosen value when there is a change in the select tag

Building a shop and almost done, but struggling with allowing customers to change product quantities in the cart and update prices dynamically. I've created a select-tag with 10 options for choosing quantities. I'd like users to be able to click ...

Conflict between the top menu and body on the HTML page is causing issues

Encountered an issue with my HTML code: CSS: .fixedmenu { overflow: hidden; background-color:rgb(153,0,51); position: fixed; /* Ensures the navbar stays in place */ top: 0; /* Positions it at the top of the page */ width: 100%; /* Occ ...