Stopping cursor hover on pseudo-element - setting pointer-events to none is not effective for this

I have a dilemma with displaying multiple links side by side and would like to separate them with dividing dashes. My solution involved utilizing the ::before pseudo element, which achieved the desired effect seamlessly.

However, a new issue arose - hovering over the dividers also triggers a hover effect on the element containing the ::before pseudo element.

You can see an example of this problem in this fiddle. When you hover over the dashes, the underline appears under the link.

In my quest to find a solution, I stumbled upon a relevant discussion on Stack Overflow. By referencing additional resources such as the Mozilla Developer Network documentation and the Can I Use page on pointer-events property, I was optimistic that this issue would be resolved. Unfortunately, it wasn't.

What am I overlooking here?

Answer №1

To achieve the desired result, modifications in the CSS file are required

.container a::before {
    content: '----';
    padding: 0 15px;
    position: absolute;
    left: -50px;
    pointer-events: none;
}
.container a {
   text-decoration: none;
   position: relative;
   margin-left: 50px;
   display: inline-block;
}

Answer №2

To achieve the desired layout, apply position:absolute to the specific element within the <a> tag in order to remove it from the normal flow of the page. Additionally, use position:relative on the parent <a> element.

Code Snippet Example:

.wrap a {
  text-decoration: none;
  margin: 0 30px;
  position: relative;
}

.wrap p {
  margin: 0;
}

.wrap {
  font-family: sans-serif;
  border: 1px solid green;
  padding: 5px;
  margin-bottom: 20px;
}

.wrap a:nth-of-type(1) {
  margin-left: 50px;
}

.wrap a::before {
  content: '----';
  position: absolute;
  pointer-events: none;
  left: -30px;
  transform: translateX(-50%);
}

.wrap a:hover {
  text-decoration: underline;
}
<div class="wrap">
  <p>These links do not have the pointer-events: none; property</p>
  <br>
  <a href="#">link text one</a>
  <a href="#">link text two</a>
  <a href="#">link text three</a>
</div>

<div class="wrap">
  <p>These do have pointer-events: none; yet their behaviour is the same as with the block above.</p>
  <br>
  <a href="#" class="pointerevents">link text one</a>
  <a href="#" class="pointerevents">link text two</a>
  <a href="#" class="pointerevents">link text three</a>
</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 scrollbar on the side of my page seems to be malfunctioning

I'm having an issue with the collapsible sidebar and tabs on my angularjs page. The scroll bar is not appearing when there is overflow in the sidebar. I've tried setting the scrollbar height to auto and overflow-y to scroll, but it's not wor ...

Expandable Bootstrap 4 panel with collapsible preview and content overflow feature

I am currently working on implementing a bootstrap setup that includes a small text preview and an expandable panel for overflowing text. The issue is that the setup was designed for Bootstrap 3, but I need it to work with Bootstrap 4 in my project using c ...

Issues with the performance of the Responsive Image Slider

Having trouble with the carousel on my website. The Navigation Bar is working, but the image slider isn't showing up despite trying multiple approaches. Bootstrap is properly linked and I've read through the documentation for the Bootstrap Carous ...

Wait for transition to finish before setting focus to text input

How can I ensure that the focus is automatically set to the text input field after a transition has ended? I want the user's keyboard input to immediately go into the text input field. Is it possible to achieve this using only CSS, or do I need to use ...

Adjustable div with varying positions and dimensions

Hey there! I'm currently working on creating a page with a variable number of resizable divs. These divs can be resized horizontally using Bootstrap's col classes (col-2 through col-12), and vertically with no limits. Additionally, new divs can b ...

In order to modify the navigation bar color, you must include the overflow property

As I work on my product landing page, I encountered an interesting issue when trying to change the color of the navigation bar. It seems that I can only do so after adding the overflow property to the ul element. Can someone shed some light on why this is ...

Incorporate Error Text Spacing in Input Group Design

I'm currently working on developing a method to incorporate space for error messages within my form input group component. The main objective is to prevent any displacement of elements on my forms when displaying error messages. In this scenario, it ...

Selenium IDE - Verify the color in a test step

I've exhausted all the suggestions I came across on Stack Overflow, but unfortunately none of them have been successful in solving my issue. Can you provide guidance on how to confirm that the background color is actually blue for the specified eleme ...

Optimal approach for reutilizing Javascript functions

After creating a simple quiz question using jQuery, involving show/hide, addClass, and tracking attempts, I am now considering how to replicate the same code for multiple questions. Would it be best practice to modify all variables in both HTML and jQuery, ...

Styling a Bootstrap dropdown menu so that an input field within it only accepts numeric digits

I am facing an issue with my input field inside a dropdown styled with CSS and I am using Bootstrap 4. When I try to enter characters, it does not work but I can input numbers without any problem. How can I resolve this? <script src="https://cdnjs.cl ...

Is it necessary for HTML "buttons" to follow the same box-model as other elements?

I recently encountered an issue with the button element and the input element when using a type of button. In both Firefox and Chrome, I noticed a behavior that seems like a bug in recent releases. However, as form elements often have exceptions to W3 rule ...

The local server is having trouble loading JavaScript

I've been troubleshooting a sleek menu design, and I'm puzzled by why it's not working on my localhost. It functioned perfectly when tested on this Codepen. However, after transferring the code to my localhost, it stopped functioning. I&apos ...

Disable the click functionality while preserving the hover feature

Due to my previous question being incorrectly marked as a duplicate, even though it wasn't, and no one is rectifying the mistake, I am re-posting my inquiry. I am dealing with an <a> element that has a default onClick function. This <a> a ...

Sub-menus at multiple levels are failing to automatically close child elements when clicked

Currently, I am tackling the challenge of creating a multi-level sub-menu that is triggered by clicks instead of hover actions. However, I'm facing an issue with closing child sub-menus when opening another one. It's crucial for all second-level ...

After deployment, certain formatting elements appear to be skewed in the React application

After developing a React app with create-react-app, everything was working perfectly. However, upon deployment, I noticed that some styles weren't showing up as expected. The majority of the styling from Material UI is intact, but there are a few dis ...

Customizing the width of an <input> element in HTML/CSS

Despite receiving some feedback, the issue regarding width control of <input> remains unresolved. This particular problem pertains to a WordPress website, but can be replicated in a very basic manner. Situation: I have created a CSS nested heading/ ...

Displaying a few squares with Angular Material's mini buttons surrounding them

Problem with displaying squares when using Angular material mini buttons in my Angular 7 project. Any suggestions on how to fix this issue? Thanks. Please take a look at the issue below: https://i.sstatic.net/VaGDV.png Here is my code: component.html ...

Using jQuery, is there a way to move an element from one div to another, but only if the destination div is currently empty

<div id="apply"></div> <div id="droppable_slots"> <div class="slot 1">1</div> <div class="slot 2">2</div> <div class="slot 3">3</div> </div> Is there a way to utilize jquery in order ...

Adjust column content to fit width, instead of setting width to 100%

To create columns for the ul, I used flex-direction: column and flex-wrap: wrap. When the elements within the ul are split into multiple columns, each column takes on the width of the widest content in that column. However, if there is only one column, it ...

Dynamic Display Picture Banner - Adjustable Layout

My home page features a full screen image header that I'm working to make responsive. The width of the image is being cut off on various screen sizes. I've attempted adjusting the height and width settings, but I want the image itself to resize ...