How to eliminate the gap between the "a" element and its ":after" pseudo-element using HTML and CSS

Currently, I am facing an issue with my code, which you can view here: https://jsfiddle.net/phpd41tb/13/

The problem involves a link created using an anchor tag, and an extension of this link using the CSS :after:

Here is the HTML structure:

<a href="some-url">Notifications</a>

And the corresponding CSS:

&:after {
        content : ">"; }

(Note that the code above is just for reference)

If you check the link provided, you will notice a gap between "Notifications" and ">". This space is not part of the actual clickable link.

My goal is to make the entire phrase "Notifications >" clickable, regardless of the space between the anchor tag and its :after pseudo-element.

I have tried various solutions suggested in different resources, such as:

Despite exploring these options, none of them seem to address my specific issue. Even attempts to modify the HTML structure by enclosing everything in another div have been unsuccessful.

Do you have any suggestions or ideas on how to resolve this? :)

Answer №1

I believe this solution works quite smoothly. I've made a modification to the translate animation by using a padding animation instead, ensuring that hovering over the link does not cause it to move away from the pointer.

Here is an extract of the code:

...
  &:after {
    padding-left: 0.5rem;
    content : ">";
    transition :opacity 0.4s ease, padding 0.4s ease;
  }
  &:hover {
    &:after {
      padding-left: 2rem;
      opacity : 0.6;
    }
  }
...

Answer №2

modify right : -15px; to right : -12px;

.menu-title h6 {
  font-size: 1.2em;
  display: block;
  transition: opacity 0.4s ease 0.4s; 
}
 .menu-title h6 a {
    color: #000000;
    position: relative;
    text-decoration: none; 
}
.menu-title h6 a:after {
      position: absolute;
      top: -1px;
      right: -12px;
      content: ">";
      transition: transform 0.4s ease, opacity 0.4s ease; 
}
.menu-title h6 a:hover:after {
      transform: translateX(10px);
      opacity: 0.6; 
}
<div class="menu-title">
  <h6>
    <a href="some-url">Notifications</a>
  </h6>
</div>

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

The absence of a datepicker in Bootstrap has become glaringly obvious

My form includes a single date input using <input type='date' class='form-control'>. When utilizing the form-control feature from Bootstrap 5, the default white color is applied to the date picker, matching the rest of the form. ...

What is the process for transferring information from HTML to Python and then receiving the output in HTML?

I am completely unfamiliar with the connection between HTML and Python, so I am reaching out for some assistance. I hope that someone here can lend me a hand. Currently, my HTML is hosted on an Apache server, and I access the website using the address "". ...

Can footer.html be omitted from the base.html file when extending it for Django?

I'm using base.html as my template which includes {% include 'footer.html' %} in every page. However, there are certain pages where I don't want the footer to appear. Is there a way to exclude the footer on specific pages using some sor ...

The website's responsiveness appears to be malfunctioning on iPhone 10 and other iOS devices

I have implemented the code below for redirecting my website in an iframe, and it displays perfectly on all browsers except Safari on iPhone. I have tested it on various models of iPhones. <head> <title>My Website</title> <meta name=" ...

Leveraging a combination of AngularJS directives within a single div element

Why can't I use multiple directives in the same div tag in AngularJS? The product names from the module are not displayed with the following HTML code: <!DOCTYPE html> <html ng-app="gemStore"> <head> <title></ti ...

Encountering an Issue When Attempting to Add a New Product Listing in Shopify Via HTTPWebRequest in C#

Below is my code snippet. I am able to successfully retrieve the token from Shopify, however, I encounter an error when trying to create a new product. I have exhausted all possible solutions without success. Any suggestions or advice would be greatly appr ...

Checkbox validation malfunctioning

I'm currently working on a attendance management project and one of the forms includes multiple checkboxes. I want to ensure that at least one checkbox is checked before the form can be submitted. I attempted to use Javascript for this, however, the i ...

Is there a way to adjust the font size of form inputs with PHP code?

I need some guidance on adjusting the font size of a form output dynamically. The goal is to allow users to select the desired font size from radio buttons, with options ranging from 15px to 30px. I have already included relevant CSS styling in the style ...

Sending fillable PDF form by email upon submission

I need to send the entire PDF document, not just the filled fields, to a specific email address when a user submits a fillable form. Previous discussions have debated whether this is possible or not, and the answer is confirmed as YES. Now I am wondering ...

Is there a way to have just the data table automatically update every 2 minutes without affecting the rest of the

I'm working on a project where I need to create an inbox mail that automatically refreshes every 2 minutes to display any new mail in the table. Can anyone help me with refreshing my datatable? ...

Unable to adjust the width of a label element using CSS specifically in Safari browsers

Here's the issue I'm facing with my HTML code <input type="checkbox" asset="AAA" name="assets[AAA]" value="AAA" id="assets[AAA]" class="c_green" checked="checked"> <label for="assets[AAA]"></label> In my CSS, I have the follow ...

Adding options to a select element in AngularJs is a simple

When working with AngularJS and a select options collection, I encountered an issue. Everything worked fine when I manually added option tags in the HTML, but it didn't work when trying to add items from Angular. This is my code: <div ng-controll ...

Error: Compilation was unsuccessful due to module not found. Unable to resolve in ReactJS

As I was wrapping up this task, an unexpected error popped up: Module not found: Can't resolve './components/Post' in ./src/pages/index.js I've tried everything to troubleshoot it but no luck. Here's a rundown of my code snippets ...

Embracing JQuery for Frontend Development with Node.js

I'm currently enhancing my node.js skills by utilizing express, and I've encountered a situation that is causing me some confusion. Essentially, when a user requests a webpage and the backend sends them the HTML page, how can I incorporate a Java ...

Tips for incorporating Angular JS variables into your JavaScript code

Currently, I am working on a project that requires me to implement a function for tagging a friend in Angular JS using ng-repeat. The function is written in JavaScript, and I am facing confusion regarding passing an ID that belongs to an Angular JS varia ...

Switching the display of the table between hidden and visible

I am struggling with a table manipulation issue where I want to hide rows with the same name and show them again on click events. However, it seems like I am missing something in my code. Can anyone help me with this? Thank you. ...

Is it possible to align an entire column to the right in the Material UI Data Grid?

I'm currently exploring Material UI and grappling with a specific challenge. Is there a method within Material UI to create a Data Grid with two columns, one left-aligned and the other right-aligned? I've managed to align the headers as desired, ...

What is the best way to display ng-repeat elements in a horizontal layout

Looking for a way to display thumbnails horizontally using ng-repeat in AngularJS and Bootstrap. Any ideas on how to achieve this with CSS or Bootstrap? <div class="row"> <ul class="col-md-4" id="phones"> <li class="thumbnail" ...

Tips to prevent modal impacts on underlying elements?

When I click on a button, a modal pops up. However, the background contents seem to spread out and sometimes scroll automatically when the modal appears. I have searched for a solution to this issue but have been unsuccessful. Can anyone please help me ide ...

The function Uri.EscapeDataString() helpfully changes the character "/" to %2F

I'm currently working on converting strings to URI format so that I can use them in URLs to display images on my webpage. My project is built using ASP.NET Core. So far, I've tried both System.Web.HttpUtility.UrlEncode() and Uri.EscapeDataString ...