在 Bootstrap 4 卡片內將影像放置在頂部


在 Bootstrap 4 中使用 card-img-top 類,將圖片放在 Bootstrap 4 中卡片的頂部 −

將圖片新增到 card 類中 −

<img class="card-img-top" src="Image-Source" alt="Alt-Text" style="width:100%">

現在新增包含標題和文字的卡主體 −

<div class="card-body">
  <h4 class="card-title">Swift 4</h4>
  <p class="card-text">Learn Swift 4</p>
  <a href="#" class="btn btn-primary">Begin</a>
</div>

以下示例說明如何在 Bootstrap 4 中將圖片放在頂部 −

示例

即時演示

<!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">
    <h3>SWIFT 4 Tutorial</h3>
    <p>Video Tutorial on Switft 4</p>
    <div class="card" style="width:350px">
      <img class="card-img-top" src="https://tutorialspoint.tw/assets/videotutorials/courses/swift_4_online_training/380_course_210_image.jpg" alt="Swift 4" style="width:100%">
      <div class="card-body">
        <h4 class="card-title">Swift 4</h4>
        <p class="card-text">Learn Swift 4</p>
        <a href="#" class="btn btn-primary">Begin</a>
      </div>
    </div>
  </div>
</body>
</html>

更新於: 2020-06-17

81 次瀏覽

開啟你的 事業

完成課程獲得認證

立即開始
廣告