Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make links work with card-img-overlay in Bootstrap v4

I'm having an issue where any Bootstrap v4 cards using the card-img-overlay to display text over an image prevents links below that image from working.

These links do work:

<div class="card" style="border-color: #333;">
    <img class="card-img-top" src="..." alt="Title image"/>
    <div class="card-inverse">
      <h1 class="text-stroke">Title</h1>
    </div>
    <div class="card-block">
      <a href="#" class="card-link">Card link</a>
      <p class="card-text">Article Text</p>
    </div>
    <div class="card-footer">
      <small class="text-muted">Date - Author</small>
    </div>
  </div>

These links do NOT work:

<div class="card" style="border-color: #333;">
    <img class="card-img-top" src="..." alt="Title image"/>
    <div class="card-img-overlay card-inverse">
      <h1 class="text-stroke">Title</h1>
    </div>
    <div class="card-block">
      <a href="#" class="card-link">Card link</a>
      <p class="card-text">Article Text</p>
    </div>
    <div class="card-footer">
      <small class="text-muted">Date - Author</small>
    </div>
  </div>

I see there is an open issue regarding this for bootstrap v4, but can anyone help with a workaround that would preserve the same look?

like image 525
AuxProc Avatar asked Mar 24 '17 21:03

AuxProc


People also ask

How do I overlay images in bootstrap?

Image Overlay: Image overlay generally refers to the image being a background image and inserting texts, and links inside of that image. It can be done using the 'card-img-overlay' property that is present in bootstrap. Also, we can do it with normal CSS along with a bootstrap theme.

What is card IMG overlay?

Card Image Overlays: card-img-overlay is used to set the image as background image of the card and add text over the image.

What is card link in bootstrap?

A card is a flexible and extensible content container. It includes options for headers and footers, a wide variety of content, contextual background colors, and powerful display options. If you're familiar with Bootstrap 3, cards replace our old panels, wells, and thumbnails.

How do you make a responsive card-deck?

Another way to make a responsive card-deck, is using responsive reset divs every x columns. This will force cards to wrap at specific breakpoints. For example: 5 on xl, 4 on lg, 3 on md, 2 on sm, etc.. The link to the responsive cards using grid doesn't quite work.


1 Answers

The overlay is position: absolute which gives that element a z-index, and the rest of the content in the card is statically positioned, so none of it has a z-index. You can give the link a z-index by adding a non-static position, and since your card link comes after the overlay in the HTML, the stacking order will put the card link's stacking order on top of the overlay.

.card-link {
  position: relative;
}
like image 166
Michael Coker Avatar answered Oct 19 '22 08:10

Michael Coker