Place the image at the top inside a Bootstrap 4 card

BootstrapWeb DevelopmentCSS Framework

Use the card-img-top class in Bootstrap 4, to set the image at the top inside a card in Bootstrap 4 −

Add the image inside the card class −

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

Now add the card body that includes title and text −

<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>

The following is an example to place an image at the top inside a Bootstrap 4 card −

Example

Live Demo

<!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://www.tutorialspoint.com/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>
raja
Published on 13-Jul-2018 08:42:48
Advertisements