Spi*_*elo 8 twitter-bootstrap bootstrap-4 bootstrap-cards
我想将一些内容放在 Bootstrap 4 卡中,并在上面有一个拉伸链接。我还想在这张卡片中包含一个按钮,它的 URL 与拉伸链接不同。
Bootstrap 的文档说:
不建议使用拉伸链接使用多个链接和点击目标。但是,如果需要,某些位置和 z-index 样式可以提供帮助。
但我无法让它工作。
我尝试过将按钮的 z-index 设置为 5000 之类的方法,但它仍然无法点击。
<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>
Run Code Online (Sandbox Code Playgroud)
我想让它可以点击按钮,而不会被拉伸的链接覆盖。
有小费吗?
kre*_*gus 20
我必须将z-index值设置为 > 1,并且必须position: relative;在元素上设置以使其可在stretched-link.
在您的情况下,这意味着:
.card .btn {
z-index: 2;
position: relative;
}
Run Code Online (Sandbox Code Playgroud)
将按钮设置为具有与 相同的 z-indexstretched-link将使按钮可点击:
.card .btn {
z-index: 1;
}
Run Code Online (Sandbox Code Playgroud)
<div>在嵌套在拉伸链接中的按钮或链接周围放置。然后为该 div 指定以下内容:
z-index:3;
position:relative;
Run Code Online (Sandbox Code Playgroud)