Excessive negative text-indent results in oversized link selections upon clicking

One technique I frequently utilize to create SEO-friendly links with images is the CSS trick of text-indent: -9999px;. Essentially, I generate a block-level anchor element with a background image and set its text-indent property to a large negative value so it remains hidden from view, which has positive effects on SEO. However, I have encountered an issue where clicking on the link causes the outline to extend off the page due to the text being positioned far away.

<div>
  <a href="#">SEO text</a>
</div>

div {
  width: 100px;
  height: 100px;
}

div a {
  display: block;
  text-indent: -9999px;
  width: 100px;
  height: 100px;
  background: url(stuff) etc...;
}

In most cases, the code above results in the outline extending beyond the 100 x 100px area when the link is clicked. Even when dimensions are defined for the parent element, the issue persists. I tried using the a span { display: none; } workaround, but I am seeking a solution that maintains the use of the text-indent trick while fixing the outline problem.

Is there anyone who knows how to resolve this issue? Should I introduce another parent element or adjust a different CSS property?

Answer №1

To prevent overflow, include the overflow:hidden property in the a tag.

div a {
  overflow: hidden;
}

By doing this, the outline border will be maintained within the specified coordinates of the element.

If you apply overflow: hidden to the div or use outline: none as suggested by Wayne Austin, it will eliminate the outline entirely, potentially leading to usability issues.

Answer №2

To fix the issue, simply include overflow: hidden in your div style

Answer №3

Check out this informative article on how to remove the annoying outline in Firefox.

Simply inserting a link seemed too simple, so I'll provide you with the CSS code instead:

a
{
  outline: none;
}
:focus
{
  -moz-outline-style: none;
}

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

Guide on incorporating `Animate.css` into an Angular application

I've been attempting to implement the bounceInUp animation from animate.css on a div upon showing it, but I can't seem to get it to work. What am I doing wrong? Can someone guide me on the correct way to achieve this effect? This is my CSS code ...

Exploring the magic of CSS hover effects combined with the

The CSS hover effect is no longer functioning after a jQuery action has been applied: Below is the CSS code currently in use: #slider-information-content{ display: inline; visibility: hidden; } #slider-information:hover #slider-information-content ...

Creating an eye-catching display with Bootstrap 4: Achieving a row of cards with varying heights

Is there a way to set up two cards next to each other in a row without one resizing to match the other? Whenever I resize the page, the cards no longer stay adjacent and collapse onto separate rows with different sizes. Manually setting the height works, b ...

Parallax effect overlay for DIV

Planning to give my website a makeover and I'm thinking of adding some parallax effects to make it more engaging. My idea is to have 3 boxes overlapping each other (with the 2nd and 3rd box appearing blurry). These boxes would be placed at the top of ...

What is the best way to align the text in the center without centering the numbers in an HTML ordered list?

I am currently working on a small widget for a webpage that displays steps in reverse order. My plan is to use an ol element and adjust the value attribute on each li tag to make the numbering of the ordered list reversed. Everything seems to be going smoo ...

Struggling with CSS Styling - Unable to align text in the middle of a table

.transfers table{ width: 650px; margin: 450px auto; border-collapse: collapse; } .transfers tr{ border-bottom: 1px solid #cbcbcb; } .transfers th{ font-family: "Montserrat", sans-serif; } .transfers th, td{ border: none; height: 30px; pa ...

Utilize jQuery to alter the global CSS declaration

I have been utilizing Twitter Bootstrap to generate form components as illustrated below. Typically, the 'submit' button should be placed outside of the 'controls' container, however, for my specific layout requirements, I need it to be ...

Incorporate Additional Rows into Grid Layout using d3

Being relatively new to d3, I have been struggling with understanding data joins. My current challenge involves adding rows to a grid layout, where each row is represented as an object with multiple slots stored in an array. Within my .join, I am attempti ...

Issue with Bootstrap dropdown menu flickering upon hover out

My minicart modal displays correctly when hovered over, but there is a flickering issue when hovering off that I'm struggling to resolve. I have made updates to the code to provide more of the menu HTML structure and a comprehensive CSS for styling t ...

Utilize BootStrap framework to embed Twitch player, ensuring it fills the entire width of its parent element

I'm new to web development and struggling to make my embedded Twitch player use its parent's full width. The height is fine, but using the d-flex class from Bootstrap makes the player extremely thin. Please review my code here: https://jsfiddle. ...

What will be the appearance of pixel widths on resolutions higher than?

What happens if I set all widths on my website to 1920px and view it on a higher resolution like 4k? Will it only take up a portion of the screen while leaving white space around it (similar to zooming out)? In essence, can I scale the entire website prop ...

How to eliminate padding between Bootstrap col-xx columns

When using Bootstrap's col-xx classes, the padding can sometimes result in wasted space on smaller screens. To address this, I have decided to remove the padding by nesting col-xx with specific CSS settings like shown below: <style> div[class^= ...

Displaying php variables using inline styles

I've come across similar inquiries but none quite like this. Within a database, I have stored hexadecimal values for the background and border colors of a specific division. I have confirmed that I am retrieving them from the database. To put it blunt ...

Column with space between arranged rows in a container

I have a container with multiple rows, each containing several columns. I am looking to adjust the spacing between each column <div class="main" style="margin-bottom:0px"> <div class="container"> <div class="row"> <div ...

Deactivate Link Using CSS while Allowing Title to be Functional

Is there a way to enable the link in CSS while still showing the title? Take a look at my code: CSS and HTML Code: .disabledLink { pointer-events: none; opacity: 0.6; cursor: default; } <a href="www.google.com" class="disableLink" title="M ...

What is the best way to personalize Material UI elements, such as getting rid of the blue outline on the Select component?

Embarking on my journey of developing a React app, I made the decision to incorporate Material UI for its array of pre-built components. However, delving into the customization of these components and their styles has proven to be quite challenging for me ...

In terms of professional design, which is the better choice - Bootstrap or Foundation?

Greetings! I am in the process of creating a website with a professional design. I'm trying to decide between using Bootstrap 3 or Foundation 5 for my CSS framework. Which one do you recommend for designing purposes? Is there another CSS framework t ...

Can someone help with the issue where the CSS field position changes when the "X" icon appears, as mentioned in the title? I am looking for a solution to fix this problem

https://i.sstatic.net/Cj8Bm.pngWhen trying to add an additional field on a page, the "X" icon appears inline with the field and causes the other fields to adjust their position. However, I want the new field to remain in the same position as the title. How ...

Vertical CSS accordion that flips when hovered within an unordered list

TASK - Flip accordion title divs vertically when hovered over. - Ensure frontface and backface display the same text and color, but with different background colors. ISSUE - I have successfully implemented a horizontal flip effect, but I am struggli ...

Conceal the footer on ionic application when the keyboard is present

Currently, I am encountering a problem with the footer-bar on a specific page. When an input field is focused, the keyboard pops up and causes the footer to overlap with it. HTML Code Snippet: <ion-view> <ion-content> <!-- Cont ...