Is there a way to customize the appearance of a clicked link using only CSS?

Is it possible to style a clicked link using only CSS in order to provide user feedback that the link has been clicked and is taking the desired action?


While I could use JavaScript to listen for click events and apply a desired class for feedback, a CSS-only solution would be preferable if possible.

Any guidance on achieving this would be greatly appreciated.

The desired effect is shown below:

https://i.sstatic.net/4BikA.gif

For a working demo/simulation of the desired behavior, please refer to this codepen.

Answer №1

Utilizing the a element to achieve a consistent look across various browsers using CSS alone can be quite challenging.

One workaround involves utilizing a radio button to achieve the desired outcome.

You can create a hidden radio button with a label styled like a link, and then use the CSS pseudo :checked selector to customize its appearance.

Here is an example of the code:

input[type=radio] {
    display:none
}

input[type=radio] + label {
    color:blue;
    text-decoration:underline;
    cursor:pointer
}

input[type=radio]:checked + label {
    color:red
}
input[type=radio]:checked + label:after {
    content:url('https://forums.adobe.com/images/jive-image-loading.gif')
}
  <input type="radio" value="" id="myRadio" />
  <label for="myRadio">
      Click me!
  </label>

Here is a jsfiddle

============ Below is my answer before updated OP ============

The a element in CSS offers several pseudo selectors that can be used to style links based on different states such as hover, visited, and active.

There are 4 main link states:

a:link    - a normal, unvisited link

a:visited - a link the user has visited

a:hover   - a link when the user hovers over it

a:active  - a link the moment it is clicked

Check out this fiddle to see these different selectors in action

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

Which language should I focus on mastering in order to create a script for my Epson receipt printer? (Check out the manual for reference)

Printer Model: TM-T88V User Manual: Receipt-marker Web template for the printer: (Provided by Epson) I'm completely new to computer languages and have been trying to understand how to print receipts. I've researched XML, HTML, CSS, and Jav ...

The YouTube video continues to play even after the container is closed

I recently worked on implementing a lightbox feature using jQuery, where a window opens upon clicking an element. Everything was working fine with images, but when I tried to open a YouTube video and play it, the video kept playing in the background even a ...

Problem with child divs escaping outside the boundaries of the parent div

I'm encountering an issue with my HTML/CSS code. I have a parent div called "secClass" which contains two child divs - secClass1 and secClass2. The problem is that the content within the child divs is not staying contained within the parent div. Can y ...

Is there a way to prevent Bootstrap-4 drop-down from automatically applying certain styles?

When creating my new website, I decided to use Bootstrap-4. However, I ran into an issue with the drop-down feature. While the drop-down works perfectly fine in the header nav-bar, it seems to be adding some unwanted inline styles when used within the page ...

Is all of the CSS stored in one or multiple files?

Will the number of CSS files on my website impact its performance? I understand the necessity of having a separate file for print styles, but I'm wondering about the other CSS files. Is it better to have all my styles in one file or split them into mu ...

Explore registrations by year and month

I am currently working on coding where a record needs to be displayed based on the date (Month, Year), for instance: 12-2022. However, with the current code I have, I am unable to achieve this. Can anyone offer some guidance on what steps I should take? ...

Issue with anchor tag not functioning properly within toggle div

Can you please help me troubleshoot why the anchor tag is not functioning properly within my div elements? When I click on the first div, the second div is displayed but the anchor tag inside the first div does not seem to be working. <script> $(&ap ...

What is causing the qtip tooltip to show up on buttons with different ids?

I have a requirement to display tooltips only for specific buttons and not for others. I am facing an issue where the tooltip intended for the TAB button is showing up when hovering over other buttons like FOO and BAR as well. Could this be due to them sha ...

Creating a perfectly centered square canvas on your screen

In the game I'm developing, I need to position a canvas at the center of the screen. The canvas should have equal width and height, covering the entire screen without overflowing, essentially creating a square shape. Is there a way to achieve this us ...

Unable to insert additional lines into diamond shape generated solely with CSS

Is there anyone out there who can assist me in creating this logo using CSS? View the image of the logo here I initially attempted to make a square with width and height, followed by experimenting with pseudo elements. However, I hit a roadblock because ...

Placing a text box above a perfectly centered container

Attempting to create an informative text box and feeling like the solution should be straightforward, but perhaps missing something crucial. After a few attempts and consulting with the powerful GPT, seeking advice here. The current appearance is as follo ...

Issue with HTML and CSS Grid alignment coupled with CSS syntax error on RBRACE

I'm in the process of updating my website indexes and decided to incorporate grids. However, when attempting to implement grids using Dreamweaver, I encountered several issues. Firstly, an error message appeared stating "Expected RBRACE at line 72, co ...

Can children with a shared CSS class be selected without prior knowledge of the class name?

While I was creating a customized theme for the online typing game, Typeracer (using Css), I encountered an issue: As the user advances in the game, the color of the typed text changes from gray to green. I want to change this green color to a different on ...

Update the color scheme according to a specified custom value

I am currently utilizing the Metronic theme for my Angular application and I have a unique requirement. I would like to allow users to personalize their own color scheme within the application. However, I am facing challenges in understanding how to dyna ...

The Bootstrap 5 class "col-md-4" seems to be malfunctioning

My goal is to create a grid layout with 3 columns and 2 rows using Bootstrap cards, but I'm encountering an issue where all the cards are centered and stacked on top of each other. Can someone please assist me in resolving this problem? Service.js co ...

Why is it necessary to utilize absolute positioning in CSS?

Check out this link According to the link, an element with absolute positioning is placed in relation to its first parent element that has a position other than static. If no such element exists, then it refers to the containing block which is <html& ...

Collecting data with Selenium as elements load [Python]

Is there a way to scrape only the newly generated items in sequence? I have a dynamic list that loads with scrolling. There are two methods I can use to scrape all generated divs: Scroll to the bottom of the list and then scrape all generated divs. Scroll ...

How can I add text to an HTML5 SVG similar to using the HTML5 <p> tag?

I am currently working on creating dynamic rectangular boxes and I am facing some difficulties with inserting text into the shapes. The SVG text requires setting x and y coordinates in separate text tags, and doesn't have built-in width and height pro ...

What is the best way to create a separate text box for each image on a page?

Is it possible to modify this code so that each text box only shows the text corresponding to its respective image? I am still relatively new to coding and am struggling to achieve the desired outcome. function displayImageInfo(text) { document.getEle ...

What's preventing my code from running the CSS class properly?

I'm puzzled as to why the "grow" class for image pop up is not working even though it's included in the echo script. Here is the PHP code snippet: echo "<a href='$file'><img class='grow' src='$file' alt=&a ...