源代碼
點擊運行
<!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.1.0/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.12.5/umd/popper.min.js"></script> <script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/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="/images/logo.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>
運行結果