What is the reason the link:visited attribute is not functioning properly for a specific page link?

I have set up links between different pages on my website. What I want is for the link that a visitor clicks on to change color once they've visited that page.

Unfortunately, this feature isn't working for me and I'm not sure why.

Here's an example of my code:

HTML:

    <div id="pageLink">
<ul>
<li><a href="index.php" id="index"><div id="indexDiv">Welcome</div></a></li>
<li><a href="about-me.php" id="aboutMe"><div id="aboutMeDiv">Bio</div></a></li>
</ul>
</div>

CSS:

    #index, #aboutMe {
text-decoration: none;

}
#index:visited, #aboutMe:visited {
color: red;
}
#indexDiv, #aboutMeDiv {
display: block;
text-decoration: none;
padding: 5px;
color: green;
font-family: Tahoma;
font-size: 20px;
}
#indexDiv:hover, #aboutMeDiv:hover {
color: gray;
}
#pageLink li{
        display: inline-block;
list-style: none;
}

Check out the live demo here.

Answer №1

there is a div nested within an a anchor tag with the style attribute set to color:green;

modify the css code snippet to:

#index:visited > div,
#aboutMe:visited > div {
  color:red;
}

now, when the anchor tag has the :visited pseudo-class, the text will appear in red.

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

Eliminating the border of a table that is contained within a cell

I am facing an issue with a nested table where I need to remove the borders from specific cells (around A and B). Here is the code snippet: <style> .withBorders tr td{ border: 1px solid black !important ; } .withBorders table. ...

What is the best approach to retrieve a JSON object from a form exception that has a specific name?

I have a certain form with input fields. My goal is to generate a JSON object from the form, excluding any input whose name is "point". However, my code doesn't seem to be working properly when I use the "not()" function. What am I doing wrong and how ...

How to implement a two-column layout within an IE contenteditable element

Currently, I am working on a contenteditable element that requires content to be displayed in a two-column layout. Users should have the ability to place the cursor anywhere within the text and move between positions using arrow keys. To achieve this, I a ...

Every time I rotate my div, its position changes and it never goes back to

Trying to create an eye test by rotating the letter "E" when a directional button is clicked. However, facing an issue where the "E" changes position after the initial click instead of staying in place. Here is a GIF showcasing the problem: https://i.stac ...

Javascript program that generates drag and drop elements using HTML5 features:

Whenever I attempt to drag and drop elements that are normally created by HTML, everything works fine. However, when I try to drag and drop elements generated by JavaScript, I encounter the following error: Uncaught TypeError: Cannot read property 'p ...

Issue with Relative Div Rendering Correctly in Firefox and IE

I have a picture nested in two divs and I wanted to overlay a piece of tape in the corner of the picture. I created a div for the tape image and positioned it at the bottom of the document with the following attributes: #tape { width: 100px; heig ...

How to position two distinct elements within a Bootstrap 5 accordion button

I am currently working with Bootstrap 5 and facing a challenge in aligning a <p> tag and a <span> to the left and right, respectively. Despite trying various approaches, I am unable to achieve the desired outcome of having them move in opposite ...

jQuery's event delegation feature fails to work in conjunction with AJAX requests

I'm currently facing issues with jQuery's on event delegation: Below is the code snippet I am working with: HTML portion: <body> <!-- Page Content Wrapper--> <div id="sb-site"> <div id="overlay">& ...

How to Safely Swap Background Images on a Website Using CSS without Affecting the Body

How can I create a background similar to this one, but using an image instead of the blue background? Take a look at I noticed that resizing the browser window doesn't affect the background. What steps should I take to achieve this effect? ...

creating a table with only two td's for formatting

My ultimate goal is to keep my web form code as minimal as possible for easier maintenance. I am currently working on creating a questionnaire and have been using two td elements for this purpose. Here is an example of what the current text structure looks ...

What is the method for identifying the selected radio button that has been dynamically generated after clicking the submit button?

Despite this question being asked multiple times before, I am struggling to find a solution that fits my specific scenario. Initially, I have a static radio button that I create. The HTML code is as follows: <body> &l ...

How to disable the Rubber/Elastic scrolling feature on your iPad?

On my webpage, there is a combination of vertical and horizontal scrolling. Everything works fine when the user swipes left or right exactly, but issues arise when the swipe is not precise along a straight line (diagonally). In this case, both vertical and ...

AngularJS utilizes JSON objects to store and manipulate data within

My task requires accessing information from an array that is nested inside another array in Json format. Here's a more detailed example: [ { "id": 1, "name": "PowerRanger", "description": "BLUE", "connections": [ {"id": 123,"meg ...

What steps should be followed to incorporate a user image and name when a user submits a comment in a functional JavaScript comments section?

After stumbling upon a comment box submitted by the user Rick Hitchcock (link here), I realized that I need to incorporate a generic user image and a username (could be anonymous) when a user submits a comment. Unfortunately, I am clueless on how to achiev ...

Customizing hover color with tailwind CSS

How can I change the color of an icon on mouseover using Tailwind CSS? I have tried to go from this https://i.sstatic.net/ObW6C.png to this https://i.sstatic.net/Tagp3.png, but it's not working. .btn { @apply agt-h-10 agt-w-10 agt-bg-zinc-100 agt- ...

Should the relative URL in a webpage's source be added to the webpage's URL?

Examining the source code of a webpage with the following URL: http://localhost:12345/web/query?name=time& Within the HTML source, I noticed a relative URL: <a href="./query?name=time&params=3">Date</a> Should the relative URL be ap ...

Unlock the power of nested dynamic content creation with JavaScript

Every time I attempt to use getelementbyid on a dynamically loaded div, I receive null as the result. This occurs even after trying both window.onload = function () { and $(window).load(function() { index.html: <main > <div id="main-div"> ...

drop down menu in navigation bar: unable to display items

I am having trouble with a dropdown menu in my code. Even though I used the code from the official Bootstrap website, the items are not appearing in the dropdown list. <nav class="navbar navbar-expand-lg navbar-dark bg-primary "> ...

Continue duplicating image to stretch header across entire screen

Looking to create a seamless connection between a Header image (2300x328px) and another image (456x328px) so that the header fills the entire width available without overlapping due to a pattern. I need the second image to extend the header to th ...

Transforming a canvas element into an image sans the use of toDataURL or toBlob

Recently, I developed a small tool which involves adding a canvas element to the DOM. Strangely, when trying to use toBlob or toDataURL, I encountered an issue with the canvas being tainted and received the error message (specifically in chromium): Uncaugh ...