Stretched link

Make any HTML element or component clickable by “stretching” a nested link via CSS.

Add .stretched-link to a link to make its containing block clickable via a ::after pseudo element. In most cases, this means that an element with position: relative; that contains a link with the .stretched-link class is clickable.

Cards have position: relative by default, so in this case you can safely add the .stretched-link class to a link in the card without any other HTML changes.

Multiple links and tap targets are not recommended with stretched links. However, some position and z-index styles can help should this be required.

Card image cap

Card title

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

Card image cap

Card title

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

Link
<div class="container">
  <div class="row">
    <div class="col-md-4">
      <div class="nj-card mb-3">
        <img class="nj-card__img nj-card__img--top" src="/assets/img/img-generic.jpg" alt="Card image cap"/>
        <div class="nj-card__body">
          <h4 class="nj-card__title">Card title</h4>
          <p>Some quick example text to build on the card title and make up the bulk of the card's content.</p>
          <button class="nj-btn nj-btn--primary stretched-link">Button</button>
        </div>
      </div>
    </div>
    <div class="col-md-4">
      <div class="nj-card mb-3">
        <img class="nj-card__img nj-card__img--top" src="/assets/img/img-generic.jpg" alt="Card image cap"/>
        <div class="nj-card__body">
          <h4 class="nj-card__title">Card title</h4>
          <p>Some quick example text to build on the card title and make up the bulk of the card's content.</p>
          <a href="#" class="nj-link stretched-link">Link</a>
        </div>
      </div>
    </div>
  </div>
</div>

Identifying the containing block

If the stretched link doesn’t seem to work, the containing block will probably be the cause. The following CSS properties will make an element the containing block:

  • A position value other than static
  • A transform or perspective value other than none
  • A will-change value of transform or perspective
  • A filter value other than none or a will-change value of filter (only works on Firefox)
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.

<div class="container">
  <div class="row">
    <div class="col-md-4">
      <div class="nj-card mb-3">
        <img class="nj-card__img nj-card__img--top" src="/assets/img/img-generic.jpg" alt="Card image cap"/>
        <div class="nj-card__body">
          <h4 class="nj-card__title">Card with stretched links</h4>
          <p>Some quick example text to build on the card title and make up the bulk of the card's content.</p>
          <p>
            <a href="#" class="stretched-link" style="position: relative;">Stretched link will not work here, because <code>position: relative</code> is added to the link</a>
          </p>
          <p class="bg-gradient-primary text-white p-1" style="transform: rotate(0);">
            This <a href="#" class="nj-link nj-link--light 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>
    </div>
</div>