📅  最后修改于: 2023-12-03 14:59:32.858000             🧑  作者: Mango
Bootstrap 5是一种流行的前端框架,它使开发人员能够更快地构建响应式网站。在Bootstrap 5中,卡是一种强大的组件,可以用于显示不同类型的内容,包括图片、文本和按钮等。在本文中,我们将介绍如何使用HTML代码构建Bootstrap 5卡。
Bootstrap 5卡的基本结构如下所示:
<div class="card">
<img src="image.jpg" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
以上代码中,.card
是Bootstrap 5卡的基本容器,.card-img-top
是图片容器,.card-title
和.card-text
是标题和文本容器,.btn
是按钮容器。需要注意的是,.card-body
包含.card-title
和.card-text
。
Bootstrap 5提供了不同类型的卡,包括基本卡、图像卡、列表卡、导航卡和卡群。下面是各种卡的HTML代码片段。
基本卡只包含标题、文本和按钮。HTML代码如下:
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
图像卡包含图像、标题、文本和按钮。HTML代码如下:
<div class="card">
<img src="image.jpg" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
列表卡包含列表、标题、文本和按钮。HTML代码如下:
<div class="card">
<ul class="list-group list-group-flush">
<li class="list-group-item">Cras justo odio</li>
<li class="list-group-item">Dapibus ac facilisis in</li>
<li class="list-group-item">Vestibulum at eros</li>
</ul>
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
导航卡包含导航栏、内容和按钮。HTML代码如下:
<div class="card">
<div class="card-header">
<ul class="nav nav-tabs card-header-tabs">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
</div>
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
卡群可以很容易地将多个卡组合在一起。HTML代码如下:
<div class="card-group">
<div class="card">
<img src="image.jpg" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
<div class="card">
<img src="image.jpg" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
<div class="card">
<img src="image.jpg" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
</div>
以上是如何使用HTML代码构建Bootstrap 5卡的简要介绍。开发人员可以根据自己的需要使用不同类型的卡,以显示不同类型的内容。希望本文能够帮助您更好地了解Bootstrap 5卡的构建。