Issue with :visited pseudo-class not functioning as intended

My code includes all four basic pseudo-classes, and they all seem to be working fine except for the :visited pseudo-class. The color property doesn't function properly, and the background property appears to be inactive. I'm not sure what the issue might be. I don't think it's due to its placement in relation to other pseudo-classes.

https://i.sstatic.net/TClOv.jpg

.navBar-Container {
  background-color: #fff;
  padding: 2px 0px;
  display: flex;
  flex-flow: row wrap;
  align-items: center;
  justify-content: center;
}

.navBar-Container .schoolBatch {
  display: flex;
  flex-flow: row wrap;
  align-items: center;
  justify-content: center;
}

.navBar-Container .schoolLogo {
  width: 80px;
  height: 60px;
}

.navBar-Container .schoolTitle {
  margin-left: 15px;
  align-items: center;
  justify-content: center;
}

.navBar-Container .schoolName {
  font-size: 1.3em;
  font-family: "Hemi Head", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  font-weight: bolder;
  text-align: center;
  color: navy;
}

.navBar-Container .schoolMotto {
  margin: 0;
  font-family: Verdana, Geneva, Tahoma, sans-serif;
  font-style: italic;
  font-size: 0.9em;
  text-align: center;
  font-weight: 500;
}

.navBar-Container ul {
  display: flex;
  flex-flow: row wrap;
  justify-content: space-evenly;
  list-style-type: none;
  padding: 0 0;
}

.navBar-Container ul>li a:link {
  color: navy;
  text-decoration: none;
  text-transform: uppercase;
  padding: 10px;
}

.navBar-Container ul>li a:visited {
  color: red;
  background-color: chartreuse;
}

.navBar-Container ul>li a:hover {
  color: white;
  background-color: navy;
}

.navBar-Container ul>li a:active {
  color: purple;
  background-color: green;
}
<div class="navBar-Container">
  <div class="schoolBatch col-4">
    <div class="schoolLogo-Container"><img src="https://via.placeholder.com/80x60" class="schoolLogo" alt="BGS Logo" /></div>
    <div class="schoolTitle">
      <div class="schoolName">BETHEL GEMINI SCHOOLS</div>
      <p class="schoolMotto">Heaven's Light, Our Ground</p>
    </div>
  </div>
  <nav class="navBar col-8">
    <ul class="navBar-Items">
      <li><a href="index.html">Home</a></li>
      <li><a href="about.html">About</a></li>
      <li><a href="admissions.html">Admissions</a></li>
      <li><a href="academics.html">Academics</a></li>
      <li><a href="gallery.html">Gallery</a></li>
      <li><a href="downloads.html">Downloads</a></li>
      <li><a href="contactus.html">Contact Us</a></li>
      <li><a href="login.html">Log In</a></li>
    </ul>
  </nav>
</div>

Answer №1

If you want to adjust the transparency between unvisited and visited links, you'll find that using `rgba()`, `hsla()`, or the `transparent` keyword won't work as expected. The default background-color value is set to `transparent`, so in order to see changes when styling `:visited` links, you need to specify a different value. Be sure to review the Limitations on visited link styles in the documentation.

One way to make this work is to update the

.navBar-Container ul>li a:link
with a background color that can be overwritten by `:visited`. Here's an example that worked for me:


.navBar-Container ul>li a:link {
  color: navy;
  text-decoration: none;
  text-transform: uppercase;
  padding: 10px;
  background-color:white;
}

For a live demonstration, check out this working example: https://jsfiddle.net/andresabadia/gna7yjtf/2/

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

Troublesome code with Ajax, Jquery, and PHP is causing issues

I've been trying to send an array from php to js using ajax, but for some reason it's not working no matter what I try. I'm convinced it must be a simple fix, but I seem to have exhausted all my options. <!doctype html> <html lang= ...

Conceal the div element if the value exceeds 0

I'm looking for a way to display a div when the number of remaining days is less than 0. I got it working on jsfiddle, but for some reason, it doesn't work anywhere else. if ($('.daysrem&a ...

Does anyone know of a CSS/JavaScript framework that can be used to replicate the look and functionality of the iOS home

I'm wondering if there is a CSS/JavaScript framework that replicates the layout of an iOS home screen. I want to create a kiosk website with a grid layout similar to Android/iOS where apps can be displayed as icons. ...

W3C validation issue: "Failure to immediately follow a start-tag with a null end-tag" and similar errors

Encountering validation errors with the following code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <hea ...

What could be causing my CSS parallax effect to not work as expected?

I have been attempting to implement the parallax image technique following the Keith Clark tutorial, but I am facing difficulties in getting it to work correctly. Utilizing the skeleton CSS framework, my goal is to recreate an existing website in order to ...

Sending data between two HTML templates in Django

Currently working on a web project with Django, still learning the ropes of Django. I'm facing an issue that has me stumped: I need to retrieve user input from one HTML search box and show it on another HTML page. This is the code for my initial ...

Unable to view Bootstrap modal upon click

Whenever I attempt to display a modal using Bootstrap, it mysteriously appears upon page refresh but fails to show up when the button is clicked. Ideally, I want the modal to only appear when the user clicks on the button. The structure of my html file lo ...

PyScript <script type="py-editor"> Issue: SharedArrayBuffer cannot be used in an insecure environment

I am currently using PyScript to execute a basic Python script within my HTML file in order to show a pandas DataFrame. However, upon loading the page in the browser and attempting to run the code block by clicking the run button, I encounter an error rela ...

What are the best methods for maintaining the appearance of my website when resizing my browser window?

I am replicating the Twitter profile page, but I am facing an issue where the text and images get jumbled together whenever I resize my browser. This results in a messy appearance of the page. How can I ensure that the text and images stay in the same rela ...

The excessive height of a Bootstrap 5 row is causing the image to overflow beyond the container

I am currently working on setting a maximum height for a banner I am designing in bootstrap5. Here is my code snippet: .banner { background: red; max-height: 50px; } <head> <title>Example</title> <meta charset="utf-8" ...

Position the div element beside the image, rather than below it

I am having an issue with Bootstrap where the card I want to display on the right of an image is appearing below it instead. I attempted to use the display: inline-block property, but unfortunately, that did not solve the problem. I also explored other so ...

Need help inserting an image into the div when the ngif condition is true, and when the ngif condition is false

Essentially, I have a situation where I am using an *ngIf condition on a div that also contains an image. This is for a login page where I need to display different versions based on the type of user. However, I'm facing an issue where the image does ...

Prevent unauthorized entry to css and javascript files

Is there a way to prevent direct access to a file? I want the file to be used on my website, but I want to block it from being accessed directly. For example, if you try to open this link: https://example.com/style.css, you will see an error message. Howev ...

Cycle through items and switch states using classList in JavaScript

Rules: Your task is to utilize javascript and the classList property to switch the elements with the .highlight class. You need to loop through all the <li> elements and change the class of .highlight on each one. Do not make any changes to the HTML ...

What is the mechanism behind the functionality of padding percentage?

HTML <div class='container'> <div class='boxContainer'> The text inside this box should be centered vertically </div> </div> CSS .container { position: relative; height: 300px; wid ...

Utilize a button to apply styles to a Span element dynamically generated with JavaScript

I am attempting to spin a span generated using JavaScript when a button is clicked. The class is added to the span, but the spinning effect does not apply. <p>Click the button to create a SPAN element.</p> <button onclick="myFunction ...

Safari experiencing a problem with the CSS mix-blend-mode: difference

I have been experimenting with a mouseover effect using mix-blend-mode. The effect is functioning as desired in Chrome and Firefox. .btn-anim { position: relative; display: inline-block; overflow: hidden; padding: 1.25rem; color: #fff; --x: 6 ...

Rearrange items in a display: contents wrapper using CSS Grid

I'm having trouble positioning descendants in a root grid while they are enclosed in a container with display: contents. The issue I am facing is that one element is not being correctly placed within the grid: .wrapper { width: 80ch; margin: a ...

Utilizing a local video file as a video background in HTML and CSS

I've hit a roadblock while attempting to set a video on my computer as the background. The video file is named "runbg.avi" and it resides in the same folder as my HTML and CSS files. After scouring through numerous websites, I encountered a couple of ...

Adjust the text to fit neatly within a circular-shaped column container

I am currently working with Bootstrap 5 and I have a row with two columns positioned next to each other. My goal is to apply rounded borders to the left column while ensuring that the content remains within the div. Below is the code snippet: <div clas ...