I want to apply a transition property to my anchor tag so that it changes color smoothly when transitioning from being visited to being hovered over

Here is the HTML content for the Main Page:

<body>
    <div class="container">
        <header>        
            <nav class="nav-items">

                    <ul>
                        <li id="li_1"><a href="index.html">First</a></li>
                        <li id="li_2"><a href="secondpage.html">Second</a></li>
                        <li id="li_3"><a href="thirdpage.html">Third</a></li>
                        <div class="clear">

                </div>
                    </ul>

This section above includes the HTML code for a list of links with A tags, styled as a floating list.

            </nav>
        </header>
    </div>
</body>

Below is the CSS styling:

*{
margin: 0px;
 padding: 0px;
}


.container{
width: 1000px;
margin: 0px auto;
background-color: #c7c7c7;

}

.nav-items{
height: 40px;
background-color: #8d8b8b;  
}
 .nav-items ul li{
list-style-type: none;
float: left;
margin: 10px 5px; 
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size: 20px;


}

.clear{

clear: both;


}


/*a{
  color:   #1f9393;
transition-property: color;
transition-duration: 2s;
}
*/

The current CSS settings are functional, but there seems to be an issue with the code below:

a:link{
color: #f0ffff;
text-decoration: none;

}
a:visited{
text-decoration: none;
color: #1f9393;
transition-property: color;
transition-duration: 2s;

}
a:hover{
color:  #2f2f2f; 
}
a:active{
color: #3e3d3b;
} 

I am attempting to have the visited link transition to the hover color, but it's not working. What could be causing this problem?

Answer №1

Make sure to include the transition in the link, outside of the :visited state.

Currently, the transition property is only applied to the link when it is in the visited state. This means that when you hover over the link and it changes from visited to hover, there is no transition effect because it is not assigned to that state. To resolve this issue, assign the transition directly to the element.

a:link{
color: green;
text-decoration: none;
transition: color 2s;

}
a:visited{
text-decoration: none;
color: red;
}
a:hover{
color: black; 
}
<a href="#">link</a>

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

What is the best way to utilize $(target) within a directive?

I created a custom directive for selecting time using two blocks. The challenge is detecting the target event on specific blocks within the directive's template. Directive Template: <div class='time-picker-container'> <div clas ...

The background image is not visible

.imagem-cortada { width: 100%; background-image: url("imagens/Vector 9.png"); } The HTML: <section class="imagem-cortada conteudo-principal"><!--inicio sobre nos--> <div class="container"> ...

How can I extract the page's output using JQuery?

Being a rookie in this area, I am eager to learn how to extract specific content from a page using AJAX in JQuery. Currently, I have been able to fetch the data of a page and display it as text: $.ajax({ type: "POST", url: "myfile.html", su ...

Showing a JSON file in an HTML page

I've been attempting to showcase a local JSON file on an HTML page. I stumbled upon some information online, but it's causing me quite a bit of confusion. Here is the JSON file I have: { "activities": [ { "name": "C:&bs ...

Embedding the @media tag directly into a class for simplification and to eliminate redundancy

For the complete css/html code sample, please visit: https://jsfiddle.net/menelaosbgr/jbnsd9hc/1/ Here are two specific definitions I am working with: /* Dropdown Content (Hidden by Default) */ .dropdown-content { display: none; position: absolut ...

Using Ajax to fetch project data from an API

Currently immersed in a personal coding project, I'm struggling to troubleshoot my code. Essentially, I need to retrieve data from an API and display it on my HTML page. The data type is "jsonp" due to CORS errors that required this workaround for de ...

Setting default data in a data table that spans multiple pages is a useful feature that can

I am facing an issue with the default settings in the data table where I need the checkbox to be pre-checked on the controller's side. The problem arises when the checkbox is not staying checked after navigating to the second page and beyond. functi ...

Only the initial external CSS ID is functional, while the second one is inactive

I am facing an issue with my table where I have applied an external CSS that uses alternating shaded rows. My aim is to have specific table cells with different background and font colors - one cell with a green background and red font, and another with a ...

Column spacing and size manipulation with Bootstrap 4

I'm currently facing an issue with aligning elements and spacing them correctly in my project. How can I resolve this using only the col class and Bootstrap 4, without resorting to CSS? I have attempted various margin spacing options like ml-md-4 and ...

The correct method for implementing server-side rendering with JavaScript

My website consists of multiple pages and utilizes React as a widget toolkit, with different bundles on each page. I am facing an issue where some widget state persists within a login session, and when the user revisits the page, the components should relo ...

Vuetify does not support Tailwind CSS styles

Initially, I integrated Tailwind CSS into my project. However, during the development process, I decided to give Vuetify a try. After adding Vuetify along with vuetify-loader, I encountered an issue where Vuetify functionality was working fine but the styl ...

Create an HTML table to view JSON data from a cell on a map

Looking to transform the JSON data into a table by organizing the information based on supplier and product. Below is the JSON input and code snippet: $(document).ready(function () { var json = [{ "Supplier": "Supplier1", "Product": "O ...

Android device automatically opens link when CSS :focus is triggered

When using a website, I apply :hover for web and :focus for touch devices on a link. However, on Android devices, when I touch the link, it triggers the :focus and then automatically opens the link. My goal is for it to trigger the :focus and only open th ...

List created using PHP

After successfully generating a list using PHP with elements selected from a database, I encountered an issue. It seems that when trying to retrieve the index of li elements using jQuery, the indices returned are only odd numbers. For example, clicking on ...

What is the best way to ensure my <h5> element fits perfectly inside its parent div vertically?

Currently facing an issue with finding a solution to my problem. The challenge involves having a header tag nested within multiple divs. Below is the structure: <div class="card"> <div class="layout-left"> <div class="card-header"> ...

Is it possible to merge elements into a carousel in the mobile display?

I have a collection of elements that I would like to combine into a swipeable carousel. Is there a way to achieve this, specifically to make it a carousel only in mobile view? If needed, here is the HTML code. Thank you for your assistance. <div class= ...

Nested arrays within an array in AngularJS can be displayed using ng-repeat

I am having trouble iterating over arrays within arrays. My goal is to create a vertical menu with button-like functionality, but I'm struggling to make it work. angular.module('NavigationApp',[]).controller('NavigationController&apo ...

Circular container div masking the nested div

Is there a CSS solution for creating a circular container with a rectangular div inside it, positioned at the bottom and masked off so that anything outside of the container's border radius is hidden? I'm looking to achieve this effect but unsure ...

What is the best way to display an AngularJS expression using a ternary operator?

Can AngularJS expressions be shown in a ternary operator? If so, can someone please provide guidance on how to achieve this? Thank you in advance. I have attempted the following, but it is not working as expected: {{ jdFile ? "Job Description File : {{fi ...

Manipulating JSON Elements using JavaScript in HTML

My objective is to alternate the visibility between the "prev" and "ext" elements retrieved from the JSON File in the following manner: Here is the link to JS Fiddle The menu bar appears as follows: [ "prev_Person1" "Person1" "ext_Person1" ... "Person2" ...