|

Stretched links

To make a link's containing block clickable using the a::after pseudo element, add .stretched-link to it. This often indicates that a link with the class .stretched-link that is contained in an element with position: relative; is clickable. Please note that due to the way CSS positions work, most table elements cannot be combined with .stretched-link.

Since UX4G cards by default have position: relative, developer can safely apply the .stretched-link class to a link in the card without making any additional HTML changes in this situation.

Stretched links are not advised for use with tap targets or multiple links. If this is necessary, some position and z-index styles can be useful.

<div class="card" style="width: 18rem;">
  <img src="..." 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="btn btn-primary stretched-link">Go somewhere</a>
  </div>
</div>
RESULT
img
Card with stretched link

Some quick example text to build on the card title and make up the bulk of the card's content.

Go somewhere

There is a need to add .position-relative here because most custom components do not come with position: relative by default in order to keep the link from extending outside of the parent element.

RESULT
...
Custom component with stretched link

This is some placeholder content for the custom component. It is intended to mimic what some real-world content would look like, and we're using it here to give the component a bit of body and size.

Go somewhere
RESULT
img
Columns with stretched link

Another instance of placeholder content for this other custom component. It is intended to mimic what some real-world content would look like, and we're using it here to give the component a bit of body and size.

Go somewhere

Identifying the containing block #

The containing block is likely to blame if the stretched link doesn't appear to function. An element will become the enclosing block if it has the CSS characteristics listed below:

  • An alternative position value to static
  • An alternative transform or viewpoint value to none
  • An aspect of transformation or perspective that will shift
  • An filter value (only supported by Firefox) other than none or a will-change filter value
<div class="card" style="width: 18rem;">
  <img src="..." class="card-img-top" alt="...">
  <div class="card-body">
    <h5 class="card-title">Card with stretched links</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>
    <p class="card-text">
      <a href="#" class="stretched-link text-danger" style="position: relative;">Stretched link will not work here, because <code>position: relative</code> is added to the link</a>
    </p>
    <p class="card-text bg-body-tertiary" style="transform: rotate(0);">
      This <a href="#" class="text-warning stretched-link">stretched link</a> will only be spread over the <code>p</code>-tag, because a transform is applied to it.
    </p>
  </div>
</div>
RESULT
Card image cap
Card with stretched links

Some quick example text to build on the card title and make up the bulk of the card's content.

Stretched link will not work here, because position: relative is added to the link

This stretched link will only be spread over the p-tag, because a transform is applied to it.