源代码 :
点击运行
<!DOCTYPE html> <html> <head> <title>Bootstrap 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css"> <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script> <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <h2>文字覆盖图片</h2> <p>如果图片要设置为背景,可以使用 .card-img-overlay 类:</p> <div class="card img-fluid" style="width:500px"> <img class="card-img-top" src="https://www.ossoft.cn/images/mix/img_avatar.png" alt="Card image" style="width:100%"> <div class="card-img-overlay"> <h4 class="card-title">John Doe</h4> <p class="card-text">Some example text some example text. Some example text some example text. Some example text some example text. Some example text some example text.</p> <a href="#" class="btn btn-primary">See Profile</a> </div> </div> </div> </body> </html>
运行结果