What could be causing the color attribute to not be applied to my navigation elements?

While working on the navigation bar styling, I encountered an issue. I added multiple <li> elements with anchor elements for links, but the text color is not loading on previously clicked links.

The files for Order and Main Page are created in the folder, while Gallery and Pricing are not present in the folder. The styled color is only loading for the existing files.

The CSS rule li a:hover is functioning correctly for all elements.

/* NAV Section - Start! */

      nav {
        background: #55595c;
        max-height: 90px;
      }

      nav img {
        position: relative;
        left: 880px;
        bottom: 55px;
        height: 120px;
        width: 150px;
      }

      .nav ul {
        list-style-type: none;
        overflow: hidden;
        display: flex;
        justify-content: center;
        position: relative;
        top: 25px;
        left: 500px;
      }

      .nav li {
        color: #4128ba;
        float: left;
        font: 16;
        text-decoration: none;
      }

      .nav li a {
        padding: 10px;
        display: block;
      }

      .nav li a:hover {
        color: #00ffff;
      }


      /* NAV Section - End! */
      
<!DOCTYPE html>
      <html lang="en">

      <head>
        <link rel="stylesheet" href="style.css">
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="icon" href="assets/logo2.png" type="icon/x-icon">
        <title>H&L Equipment - Main!</title>
        <link rel="stylesheet" href="style.css">
      </head>

      <body>
        <!-- Navigation Bar - Start! !-->
        <nav>
          <div class="nav">
            <ul>
              <li><a href="order.html">Order</a></li>
              <li><a href="#">Pricing</a></li>
              <li><a href="#">Gallery</a></li>
              <li><a href="index.html">Main Page</a></li>
            </ul>
          </div>
          <div class="img">
            <img src="assets/logo2.png">
          </div>
        </nav> <br>
        <!-- Navigation Bar - END! !-->
        <!-- Showcase - Start! !-->
        <h2 id="h2-showcase">What do we offer?</h2>
        <p id="p-showcase">We offer multiple high-quality bodybuilding equipment!</p> <br> <br>
        <!-- Showcase - End! !-->
      </body>
      <!-- Showcase Photos - Start! !-->
      <div class="showcase-photos">
      </div>
      <!-- Showcase Photos - End! !-->

      <br> <br>

      <!-- Login Form !-->

      </html>

https://i.sstatic.net/R15Kh.png

Answer №1

In the default browser stylesheet, the color property for links and visited links is assigned a specific color rather than inheriting it.

As a result, links retain their default color and do not adopt the color set on the parent li elements.

To change the link color, you must directly target the links themselves instead of their container element.

Answer №2

Quentin makes a great point, and I've also taken the liberty of tidying up your code a bit. Instead of using the .nav class, you can simplify things by utilizing the appropriate HTML tag. Additionally, implementing a flexbox layout will streamline your positioning tasks and enhance the overall responsiveness of your design. Check out this guide for more information: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

If you plan to apply styling to images, you can do so by assigning classes directly to them without the need for an extra div unless it serves a specific purpose.

/* NAV Section - Start! */

*,
 ::before,
 ::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

nav {
  display: flex;
  flex-direction: row;
  justify-content: end;
  background: #55595c;
  max-height: 90px;
  width: 100vw;
}

nav img {
  height: auto;
  width: 150px;
}

nav ul {
  list-style-type: none;
  overflow: hidden;
  display: flex;
  justify-content: end;
  align-items: center;
}

nav li {
  color: #4128ba;
  float: left;
  font: 16;
  text-decoration: none;
}

nav a {
  color: red;
  padding: 10px;
  display: block;
}

nav a:hover {
  color: #00ffff;
}


/* NAV Section - End! */
<!DOCTYPE html>
<html lang="en">

<head>
  <link rel="stylesheet" href="style.css">
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="icon" href="assets/logo2.png" type="icon/x-icon">
  <title>H&L Equipment - Main!</title>
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <!-- Navigation Bar - Start! !-->
  <nav>
    <img class="img" src="http://via.placeholder.com/150x150">
    <ul>
      <li><a href="order.html">Order</a></li>
      <li><a href="#">Pricing</a></li>
      <li><a href="#">Gallery</a></li>
      <li><a href="index.html">Main Page</a></li>
    </ul>
  </nav> <br>
  <!-- Navigation Bar - END! !-->
  <!-- Showcase - Start! !-->
  <h2 id="h2-showcase">What do we offer?</h2>
  <p id="p-showcase">We offer multiple high-quality bodybuilding equipment!</p> <br> <br>
  <!-- Showcase - End! !-->
</body>
<!-- Showcase Photos - Start! !-->
<div class="showcase-photos">
</div>
<!-- Showcase Photos - End! !-->

<br> <br>

<!-- Login Form !-->

</html>

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

Converting JSON data into an HTML table with the help of ASP.NET Web API

I have successfully implemented a web API using .NET Web API. The JSON data is returned via the API URL call /api/v1/Au/Get. However, I am facing an issue as I am unsure of how to use this data effectively since the URL path is my API call and not associat ...

Using automatic margins with tabs in the latest version of Bootstrap, known as Bootstrap

Currently exploring Bootstrap 5 and still getting the hang of it - so please bear with me if this question seems a bit rudimentary! I've been experimenting with tabs to create tabbed panes of local content. I've followed the code provided in the ...

Is it possible that the jQuery toggleClass fade is functioning with one class but not the other?

I'm struggling to make my i elements lose the outline class on hover. However, instead of smoothly transitioning out, the class is simply lost and added back immediately. Strangely enough, when I use the same code with a background class, it works per ...

JSON format for capturing country-specific information such as mailing address and phone number requirements

Hey everyone, I'm looking for a website that provides country-specific form fields for mailing addresses and phone numbers in JSON format. I want to be able to iterate through the JSON data, generate HTML, and ensure that my address and phone number f ...

What steps should I take to set up my React project in order to eliminate .html extensions from the html files within the public

Currently, I am tackling a project that involves integrating a React app with a static website. Simply converting the HTML to JSX is not feasible because the website utilizes custom CSS that React cannot easily render without significant refactoring. I ha ...

get the second child element using javaScript

Alright, I am working on a school assignment where I have 4 containers. When you click a button in a container, a popup shows the image and heading of the container you clicked on. I have figured out how to get the image to display, but I'm struggling ...

how to quietly change the focus of an element using jquery and css?

Whenever I modify the CSS of a scrolled-past element, the view abruptly jumps to that particular div (by scrolling up) upon applying CSS changes using .css(...). Something as simple as adjusting the background-color can trigger this effect. Is there a wor ...

Is it possible to navigate to an HTML element in the template of a different component?

One of my components contains a navigation bar with a function that allows users to scroll to a specific element on the page. Here is the template for the Navbar: <a class="nav-link" (click)="scroll(services)">Services</a> The code for the N ...

What could be the reason for the lack of styling on the select element when using PaperProps in the MenuProps of my Select component?

I've been struggling to remove the white padding in this select box for a while now. I've tried countless variations and places to tweak the CSS with no success. Any suggestions on how to make it disappear? The project is using MUI 5, and I even ...

Floating divs failing to clear properly in Internet Explorer

Encountered a persistent bug that only seems to occur in Internet Explorer. I have set up a jsFiddle to showcase the issue. <div class="container" style="width: 802px;"> <div class="block"></div> <div class="block"></div> ...

Unable to use jQuery for dynamically populating select options with values retrieved via AJAX calls

Trying to update the value of a select option using this method doesn't seem to work when the options are loaded via AJAX. The goal is to reset the option back to its original value after a page refresh due to form validation issues such as missing r ...

Enhancing Websites with the Power of Jquery and CSS Animation

I am trying to slow down the animation of increasing and decreasing height using jQuery. Currently, I am using .css() to adjust the height of a div element. Can someone please provide assistance? <script> $(document).ready(function(){ $(".st ...

Buttons and JavaScript: A Comprehensive Compilation

I'm facing an issue with my HTML buttons and JavaScript. When a button is clicked, an AJAX call should be triggered to display data. However, JavaScript seems unable to detect the button. Below is the HTML code: <ul> <li><input ...

Leveraging JSON data with jQuery's ajax function

Utilizing jQuery to retrieve data from this API () has been a success. I have successfully fetched the main details such as "name", "height", and "mass". However, I am facing a challenge when trying to access the values of "homeworld", "films", "species", ...

The proper way to apply the margin-top property in javascript using the DOM style

Struggling to get my div element perfectly centered on the screen. It's aligned in the center, but the top margin stubbornly refuses to budge from the top. I attempted setting divElement.style.marginTop = "100px";, yet saw no change in position. //t ...

MDBootstrap Datatable Failing to Apply Automatic Styling Properly

Working on my Laravel project, I decided to use MDBootstrap to style a datatable. However, after running the script at the bottom of my page to create the datatable, I noticed that the Search function and pagination were not styled and did not have classes ...

Troubleshooting: Javascript Opacity Slider Malfunctioning on Internet Explorer

I was looking for a way to change the color of an image using a slider. I decided to tweak some Javascript code so that it alters the opacity of a different colored image layered on top of the original one as the slider is adjusted. Additionally, I incorpo ...

Is it possible to change the title of a QGroupBox using HTML expressions in Python?

Does anyone know how to set the title of a QGroupBox with HTML expressions in a Python program? For example, using ABC for subscript. If you have any insights or solutions, please share! Thank you. ...

Replacing CSS classes in ReactJS

I am looking to customize the CSS of certain React classes in order to achieve a specific look for an input in a form. My goal is to have the input displayed as a straight line without any background color. Here is the CSS code I have been using: .text-li ...

Create a hover effect for a list item that displays an image and text simultaneously

Is there a way to create an on-hover effect for my icon when hovering over a list item in my dropdown menu? I've shared a codepen link where you can see the issue I'm facing. Everything highlights except the image because I'm only changing ...