将图片转换为 Bootstrap 4 卡片背景

bootstrapweb developmentcss framework更新于 2024/1/12 4:28:17

使用 card-img-overlay 类将图片转换为卡片背景。

您需要先设置 <img> 元素,然后使用 card-img-overlay 类,如以下代码片段所示 −

<div class="card img-fluid" style="width:500px">
  <img class="card-img-top" src="https://www.cainiaomax.com/avro/images/apache-avro-mini-logo.jpg" alt="Card image" style="width:100%">
  <div class="card-img-overlay">
    <h4 class="card-title">Avro</h4>
    <p class="card-text">Tutorial for Apache Avro</p>
    <a href="#" class="btn btn-info">Learn</a>
  </div>
</div>

让我们看一个例子来学习如何将图像转换为 Bootstrap 卡片背景 −

示例

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
  </head>

<body>

<div class="container">
  <h2>Apach - Tool for Hadoop</h2>
  <div class="card img-fluid" style="width:500px">
    <img class="card-img-top" src="https://www.cainiaomax.com/avro/images/apache-avro-mini-logo.jpg" alt="Card image" style="width:100%">
    <div class="card-img-overlay">
      <h4 class="card-title">Avro</h4>
      <p class="card-text">Tutorial for Apache Avro</p>
      <a href="#" class="btn btn-info">Learn</a>
    </div>
  </div>
</div>

</body>
</html>

相关文章