当前阅读教程:Bootstrap4教程 > 图片卡片 | |
阅读(22555525) 收藏 赞(5685) 分享 | |
上一篇: 标题、文本和链接 | 下一篇: Bootstrap4 下拉菜单 |
我们可以给 <img> 添加 .card-img-top(图片在文字上方) 或 .card-img-bottom(图片在文字下方 来设置图片卡片: 实例 <div style="width:400px"> <img src="img_avatar1.png" alt="Card image"> <div> <h4>John Doe</h4> <p>Some example text.</p> <a href="#" class="btn btn-primary">See Profile</a> </div> </div> 完整代码 <!DOCTYPE html> <html> <head> <title>Bootstrap 实例(小白教程网 2d5.net)</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> <h2>图片卡片</h2> <p>图片在头部 (card-img-top):</p> <div style="width:400px"> <img src="https://static.runoob.com/images/mix/img_avatar.png" alt="Card image" style="width:100%"> <div> <h4>John Doe</h4> <p>Some example text some example text. John Doe is an architect and engineer</p> <a href="#" class="btn btn-primary">See Profile</a> </div> </div> <br> <p>图片在底部(card-img-bottom):</p> <div style="width:400px"> <div> <h4>Jane Doe</h4> <p>Some example text some example text. Jane Doe is an architect and engineer</p> <a href="#" class="btn btn-primary">See Profile</a> </div> <img src="https://static.runoob.com/images/mix/img_avatar.png" alt="Card image" style="width:100%"> </div> </div> </body> </html> 效果图 如果图片要设置为背景,可以使用 .card-img-overlay 类: 实例 <div style="width:500px"> <img src="img_avatar1.png" alt="Card image"> <div> <h4>John Doe</h4> <p>Some example text.</p> <a href="#" class="btn btn-primary">See Profile</a> </div> </div> 完整代码 <!DOCTYPE html> <html> <head> <title>Bootstrap 实例(小白教程网 2d5.net)</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> <h2>文字覆盖图片</h2> <p>如果图片要设置为背景,可以使用 .card-img-overlay 类:</p> <div class="card img-fluid" style="width:500px"> <img src="https://static.runoob.com/images/mix/img_avatar.png" alt="Card image" style="width:100%"> <div> <h4>John Doe</h4> <p>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> 效果图 |
|
上一篇: 标题、文本和链接 | 下一篇: Bootstrap4 下拉菜单 |