Skip to main content

Helpers

Stretched link

Make a whole card or media object clickable by stretching one link over its containing block.

How it works

.stretched-link adds a ::after pseudo-element that is absolutely positioned to cover the link's containing block. The nearest ancestor with position: relative (or any non-static position, or a transform) becomes the click target. Only one stretched link per containing block.

The link itself stays a normal link: it is still in the tab order, screen readers read its text, and the theme's gold hover colour and focus ring still apply to it.

Cards

.card already has position: relative, so the whole card becomes clickable.

Event poster
Night of Champions '97

Six title matches, one steel cage. The whole card is the link.

Get tickets
HTML
<div class="card" style="width: 18rem">
  <div class="ratio ratio-16x9 card-img-top text-bg-navy"><div class="d-flex align-items-center justify-content-center">Event poster</div></div>
  <div class="card-body">
    <h5 class="card-title">Night of Champions '97</h5>
    <p class="card-text">Six title matches, one steel cage. The whole card is the link.</p>
    <a href="#!" class="btn btn-primary stretched-link">Get tickets</a>
  </div>
</div>

Custom components

Most other elements are position: static, so add .position-relative to the block you want to be clickable. The media-object pattern below relies on it.

Headshot
Custom component with stretched link

The flex wrapper has .position-relative, so the link covers the headshot and the text.

Go somewhere
HTML
<div class="d-flex position-relative">
  <div class="flex-shrink-0 ratio ratio-1x1 text-bg-gold rounded-1 me-3" style="width: 6rem"><div class="d-flex align-items-center justify-content-center">Headshot</div></div>
  <div>
    <h5 class="mt-0">Custom component with stretched link</h5>
    <p>The flex wrapper has <code>.position-relative</code>, so the link covers the headshot and the text.</p>
    <a href="#!" class="stretched-link">Go somewhere</a>
  </div>
</div>

Columns in a .row are already position: relative, so the link stretches over the column.

Belt
Columns with stretched link

With .position-static on the column, the containing block is the .row instead.

Go somewhere
HTML
<div class="row g-0 bg-body-secondary border rounded-1 overflow-hidden" style="max-width: 32rem">
  <div class="col-md-4">
    <div class="ratio ratio-1x1 text-bg-cream"><div class="d-flex align-items-center justify-content-center">Belt</div></div>
  </div>
  <div class="col-md-8 position-static p-4 ps-md-0">
    <h5 class="mt-0">Columns with stretched link</h5>
    <p>With <code>.position-static</code> on the column, the containing block is the <code>.row</code> instead.</p>
    <a href="#!" class="stretched-link">Go somewhere</a>
  </div>
</div>

Identifying the containing block

If the stretched link does not seem to cover what you expect, an element between the link and the intended wrapper is creating its own containing block. Any of these will do that:

  • A position other than static.
  • A transform, perspective or filter value other than none.
  • will-change: transform or will-change: perspective.
  • contain: paint or similar containment.

Hover effects on cards that use transform are the usual culprit.

Only the body is clickable

The .card-body has .position-relative, so it — not the card — is the containing block.

Go somewhere
HTML
<div class="card" style="width: 18rem">
  <div class="card-body position-relative">
    <h5 class="card-title">Only the body is clickable</h5>
    <p class="card-text">The <code>.card-body</code> has <code>.position-relative</code>, so it — not the card — is the containing block.</p>
    <a href="#!" class="stretched-link">Go somewhere</a>
  </div>
  <div class="card-footer text-body-secondary">This footer is not part of the link.</div>
</div>

CSS

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

Because the pseudo-element has z-index: 1, other buttons inside the same containing block are covered. Give them .position-relative and a higher .z-2 if they must stay clickable; see z-index utilities.