.card-img-top 课堂
在 Bootstrap 中使用 card-img-top 类在卡片顶部设置图片 −
<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 中实施 card-img-top 类 −
示例
<!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.com/assets/videotutorials/courses/swift_4_online_training/380_course_210_image.jpg" alt="Swift4" 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>
广告