I'd like to put some content in a Bootstrap 4 card with a stretched link over it. I'd also like to include a button in this card which has a URL different to the stretched link.
Bootstrap's documentation says:
Multiple links and tap targets are not recommended with stretched links. However, some position and z-index styles can help should this be required.
But I can't get it to work.
I've tried things like setting the z-index of the button to 5000, but it's still not clickable.
<div class="card">
<div class="card-body">
<div class="row">
<div class="col align-self-center">
<h5 class="card-title">This is a card</h5>
<h6 class="card-subtitle mb-2 text-muted">It has a button in it</h6>
<p class="card-text">How do I make the button rise up above the stretched link?</p>
</div>
<div class="col-auto align-self-center">
<a class="btn btn-primary" href="https://www.stackoverflow.com" role="button">Button Link</a>
</div>
<a href="https://www.duckduckgo.com" class="stretched-link"></a>
</div>
</div>
</div>
card example
I'd like to make it so the button is clickable without the stretched link covering it.
Any tips?
Fancy larger or smaller buttons? Add .btn-lg or .btn-sm for additional sizes. Create block level buttons—those that span the full width of a parent—by adding .btn-block .
Bootstrap allows us to align elements by using the utility class float. As we want to align the button to the right side of the text box, we have to use the float-right class.
Does BTN-block work in Bootstrap 5? btn-block bootstrap not working In Bootstrap 5.0. x, btn-block is depreciated, and to get a full width button you can use a grid system and use col-12 in the button class.
Add class .btn-block to create a block level button that spans the entire width of the parent element.
I had to set z-index
to a value > 1, and had to set position: relative;
on the element to make it clickable on top of the stretched-link
.
In your case, that means:
.card .btn {
z-index: 2;
position: relative;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With