📜  如何在Bootstrap 4中使用card-img-overlay类上的链接?(1)

📅  最后修改于: 2023-12-03 15:24:27.043000             🧑  作者: Mango

如何在Bootstrap 4中使用card-img-overlay类上的链接?

在Bootstrap 4中,card-img-overlay是一个类,用于在卡片图片上添加叠加层。在卡片上添加链接可以使卡片具有交互性,增强用户体验。

使用方法

要使用card-img-overlay类上的链接,需要在卡片图片上添加a标签,并将其wrap在card-img-overlay内,如下所示:

<div class="card bg-dark text-white">
  <img src="https://placeholder.com/500x300" class="card-img" alt="...">
  <div class="card-img-overlay">
    <a href="#" class="stretched-link"></a>
    <h5 class="card-title">Card title</h5>
    <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
    <p class="card-text">Last updated 3 mins ago</p>
  </div>
</div>

在card-img-overlay内部添加a标记并将其拉伸,使其占据整个覆盖图像的空间,就可以将链接应用于整个覆盖层。

示例

下面是使用card-img-overlay类上的链接的完整示例:

<div class="card-deck">
  <div class="card">
    <div class="card-img">
      <img src="https://via.placeholder.com/500x300" alt="Card image cap">
      <div class="card-img-overlay">
        <a href="#" class="stretched-link"></a>
        <h5 class="card-title">Card title</h5>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
        <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
      </div>
    </div>
  </div>
  <div class="card">
    <div class="card-img">
      <img src="https://via.placeholder.com/500x300" alt="Card image cap">
      <div class="card-img-overlay">
        <a href="#" class="stretched-link"></a>
        <h5 class="card-title">Card title</h5>
        <p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p>
        <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
      </div>
    </div>
  </div>
  <div class="card">
    <div class="card-img">
      <img src="https://via.placeholder.com/500x300" alt="Card image cap">
      <div class="card-img-overlay">
        <a href="#" class="stretched-link"></a>
        <h5 class="card-title">Card title</h5>
        <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p>
        <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
      </div>
    </div>
  </div>
</div>

card-img-overlay类示例

结论

在Bootstrap 4中,可以轻松地使用card-img-overlay类和a标记在卡片图片上创建链接。通过这种方法,可以增加与用户的交互性,从而增强用户体验。