Hide anchor text from bootstrap stretched link with ::after selector

Viewed 17

I basically have a card layout and all these cards are made visitable with a link by using the bootstrap stretched-link class.
But since I want my page to be fully SEO friendly, I also added a text to my anchor which kind of makes no sense in a card layout, hence why I wanted to hide the text but still profit from the SEO advantages.

Here comes the problem:
Commonly I used to simply set the font-size of my anchor text to 0, but in this scenario it seems to break the ::after selector and I am still not sure why.

I wanted to ask if anyone knows a possible CSS hack to hide the anchor text but still make the stretched link work.


This is what the stretched-link does btw:

.stretched-link::after {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1;
    content: "";
}
1 Answers

Set its opacity: 0 so it won't be seen. Set its dimension also to zero so it won't affect position of other elements, but yet maintain clickability of stretched link.

.my-link {
  opacity: 0;
  overflow: hidden;
  height: 0;
  width: 0;
  display: block;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">

<div class="card" style="width: 18rem;">
  <img src="https://picsum.photos/300/150" class="card-img-top" alt="...">
  <div class="card-body">
    <h5 class="card-title">Card with stretched link</h5>
    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
    <a href="#" class="my-link stretched-link">SEO FRIENDLY</a>
  </div>
</div>

Related