:active state not functioning correctly

I've utilized the :after and :before pseudo-elements to create a border effect when hovering over the navigation links. I've been trying to achieve the same border effect in the :active pseudo-class as well. Can someone please guide me on how to accomplish this? Below is the code snippet I have been working on:

nav ul .u {
  position: relative;
  color: f4f4f4;
}
nav ul li a:after,
nav ul li a:before {
  content: " ";
  position: absolute;
  display: block;
  width: 0;
  height: 2px;
  transition: width .2s;
}
nav ul li a:after {
  left: 10%;
  bottom: -5px;
  background-color: #f1c40f;
}
nav ul li a:before {
  right: 10%;
  top: -5px;
  background-color: #f1c40f;
}
nav ul li a:hover {
  color: #F4F4F4;
}
nav ul li a:hover:before,
nav ul li a:hover:after {
  width: 80%;
}
nav ul .active a:after,
nav ul .active a:before {
  content: " ";
  position: absolute;
  display: block;
  width: 0;
  height: 2px;
  transition: width .3s;
}
nav ul .active a:after {
  left: 10%;
  bottom: -5px;
  background-color: #f1c40f;
}
nav ul .active a:before {
  right: 10%;
  top: -5px;
  background-color: #f1c40f;
}
<nav>
  <ul>
    <li class="active"><a class="u" href="#">Home</a></li>
    <li><a class="u" href="#">About</a></li>
    <li><a class="u" href="#">Specials</a></li>
  </ul>
</nav>

Answer №1

Simply include the following code in your CSS:

nav ul li a:active {
  color: yellow;
}

By adding this snippet, whenever a user clicks on a link in your navigation, the color of the link will change to yellow as defined by the :active class.

For further information on the :active class, you can visit the following link:

https://developer.mozilla.org/en-US/docs/Web/CSS/%3Aactive

Answer №2

Incorrect Usage Detected.

Kindly review the definition of "after": The ::after pseudo element enables the insertion of content onto a webpage through CSS, eliminating the need to include it in the HTML.

Consider utilizing standard hover styling to meet your needs.

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

Accessing and displaying a randomly selected PDF file from a directory using HTML coding

Welcome to my recipe collection website where I document all the delicious recipes I love to eat. One feature I would like to add is a 'random' button, so that a recipe will be selected at random for me without having to make a decision. Althou ...

Is there a different option to <br /> that allows me to adjust the spacing between lines?

Consider the example below: Line1 <br /> Line2 To create a line break between Line1 and Line2, I have utilized <br />. However, due to lack of cross-browser compatibility in setting the height of br, I am seeking an alternative approach. Any ...

What is the best way to trigger a PHP function using a button click event?

One of the functionalities I have is a reset button that's supposed to switch out the JSON data displayed here with a different dataset called defaultStats.json (that I've saved for this purpose). Here's a snapshot of what the current databa ...

Developing a feature that allows users to switch between different sets of information

I'm currently exploring a new project and attempting to design a toggle that switches between monthly and annual payments based on the user's selection, much like the functionality found here: . At present, I have implemented two sets of price c ...

Creating space between flex items in Slick Carousel with Vue

This is my current Slick Carousel. There are 4 items in a row, and I am looking to insert some margin between each item while maintaining the existing aspect-ratio: 1.3/1; I'm struggling with overriding the classes from vue-slick-carousel. Does any ...

No visible changes resulting from the CSS file

My project includes a CSS file named default.css, but it doesn't seem to be working or making any changes to my page This is the content of default.css: .feedbackText{ display: none; text-align: center; margin-left: 50px; color: blue; } In the HTML ...

sticky placement changes when option is chosen

I'm experimenting with the CSS style called position: sticky and I've encountered an issue. Everything works perfectly until the select element is activated, causing the page to scroll back to the original position of the sticky element. <div ...

What is the best way to horizontally center a div while ensuring the content within the div stays aligned?

I'm attempting to align a div in the center while maintaining the position of its contents. Check out my code snippet: <style> .wrap{ position: relative; } .character{ position: absolute; bottom: -10%; left: 0; heigh ...

Tips for saving data from dynamically created input and select boxes

I have developed a webpage where users can add or delete rows by clicking on the addrow and delrow buttons. Everything is working fine so far. The issue I am facing now is that I need to store the values of dynamically generated fields using the post metho ...

Utilizing CSS to create a text box with angled left and right edges

.soccer-field{ width: 50%; box-shadow: 0 4px 12px 4px rgba(0,0,0,0.2); } .text-sf p{ float:left; } .right-curve{ float:right; width: 0; height: 0; border-style: solid; ...

Modify the arrow design for the expansion panel's default arrow style

Looking to customize the design of an angular expansion panel? Check out the images below for inspiration: Before Customization: https://i.sstatic.net/4u6NS.png After Customization (Not expanded): https://i.sstatic.net/8N6Br.png After Customization (E ...

Tips for maintaining the size of a div container

Take a look at the following code snippet: <head> <title></title> <style> .section_divs { background-color: lightblue; float: left; } #section_empty { background-color: tomato; width ...

Refresh DataTable while making a fetch request

Here is the HTML code snippet where I want to apply DataTable: <div id="reportrange" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc;"> <span></span> </div> <table id=" ...

The z-index property seems to be malfunctioning when used in conjunction with the relative and absolute positioning

I have created a dropdown menu using pure CSS3, but I am facing an issue with the z-index property. The dropdown list is appearing above the menu when it should be dropping below it. I have spent all day trying to troubleshoot this problem to no avail, so ...

The Cordova minification tool fails to compress files within the browser platform

I recently installed the cordova-minify plugin to compress the javascript code in my Cordova app. When I tried running the command: cordova build browser An output message appears: cordova-minify STARTING - minifying your js, css, html, and images. ...

`Can you guide me on the proper path for designing this website layout?`

As I embark on creating my first website, I have a specific vision in mind. I want the full display on a computer screen to show all the information and links without any need for scrolling. However, when the window is resized to smaller screens, I would l ...

Python code using selenium syntax cannot be run in Microsoft Visual Studio Code

Python code containing selenium syntax is correctly written, however, when attempting to execute it in visual studio code, the entire script gets underlined in red. The exact cause of this issue remains a mystery. Presented below is the specific portion ...

A guide to placing tooltips dynamically in highcharts column charts

I am encountering an issue with tooltips in Highcharts column charts. The problem arises when the series fill up my chart, causing the tooltip to be hidden below the series and cut off by the end of the div. You can see an example here: https://i.stack.i ...

Experiencing difficulties with the footer design in bootstrap framework

After creating a basic web page, I encountered an issue with the footer. No matter what adjustments I make, the text is not centered and it does not stay fixed when changing the browser height. To view the code snippet and preview, visit: ...

retrieve user input from various angular 6 components

Currently, I am in the process of developing a small web-based game using Angular 6. Within this project, I have two key components - play.component and setup.component. The main concept is to allow users to customize elements such as difficulty within the ...