最基本的列表组是一个包含列表项的无序列表:
要创建基本列表组,请使用<ul>
具有类的元素.list-group
, 和<li>
具有类的元素.list-group-item
:
<ul class="list-group">
<li class="list-group-item">First item</li>
<li class="list-group-item">Second item</li>
<li class="list-group-item">Third item</li>
</ul>
亲自试一试 »
使用.active
类来突出显示当前项目:
<ul class="list-group">
<li class="list-group-item active">Active item</li>
<li class="list-group-item">Second item</li>
<li class="list-group-item">Third item</li>
</ul>
亲自试一试 »
要创建包含链接项目的列表组,请使用<div>
代替<ul>
和<a>
代替<li>
。 (可选)添加.list-group-item-action
如果你想在悬停时使用灰色背景颜色,请使用以下类:
<div class="list-group">
<a href="#" class="list-group-item list-group-item-action">First item</a>
<a href="#" class="list-group-item list-group-item-action">Second item</a>
<a href="#" class="list-group-item list-group-item-action">Third item</a>
</div>
亲自试一试 »
这个.disabled
类为禁用的项目添加较浅的文本颜色。当在链接上使用时,它将消除悬停效果:
<div class="list-group">
<a href="#" class="list-group-item disabled">Disabled item</a>
<a href="#" class="list-group-item disabled">Disabled item</a>
<a href="#" class="list-group-item">Third item</a>
</div>
亲自试一试 »
使用.list-group-flush
类来删除一些边框和圆角:
<ul class="list-group list-group-flush">
<li class="list-group-item">First item</li>
<li class="list-group-item">Second item</li>
<li class="list-group-item">Third item</li>
<li class="list-group-item">Fourth item</li>
</ul>
亲自试一试 »
如果您希望列表项水平显示而不是垂直显示(并排而不是彼此重叠),请添加.list-group-horizontal
上课到.list-group
:
<ul class="list-group list-group-horizontal">
<li class="list-group-item">First item</li>
<li class="list-group-item">Second item</li>
<li class="list-group-item">Third item</li>
<li class="list-group-item">Fourth item</li>
</ul>
亲自试一试 »
上下文类可用于为列表项着色:
为列表项着色的类是: .list-group-item-success
,list-group-item-secondary
,list-group-item-info
, list-group-item-warning
,.list-group-item-danger
,.list-group-item-primary
,list-group-item-dark
和list-group-item-light
,:
<ul class="list-group">
<li class="list-group-item list-group-item-success">Success item</li>
<li class="list-group-item list-group-item-secondary">Secondary item</li>
<li class="list-group-item list-group-item-info">Info item</li>
<li class="list-group-item list-group-item-warning">Warning item</li>
<li class="list-group-item list-group-item-danger">Danger item</li>
<li class="list-group-item list-group-item-primary">Primary item</li>
<li class="list-group-item list-group-item-dark">Dark item</li>
<li class="list-group-item list-group-item-light">Light item</li>
</ul>
亲自试一试 »
<div class="list-group">
<a href="#" class="list-group-item list-group-item-action">Action item</a>
<a href="#" class="list-group-item list-group-item-action list-group-item-success">Success item</a>
<a href="#" class="list-group-item list-group-item-action list-group-item-secondary">Secondary item</a>
<a href="#" class="list-group-item list-group-item-action list-group-item-info">Info item</a>
<a href="#" class="list-group-item list-group-item-action list-group-item-warning">Warning item</a>
<a href="#" class="list-group-item list-group-item-action list-group-item-danger">Danger item</a>
<a href="#" class="list-group-item list-group-item-action list-group-item-primary">Primary item</a>
<a href="#" class="list-group-item list-group-item-action list-group-item-dark">Dark item</a>
<a href="#" class="list-group-item list-group-item-action list-group-item-light">Light item</a>
</div>
亲自试一试 »
结合.badge
具有实用程序/帮助程序类的类,用于在列表组内添加徽章:
<ul class="list-group">
<li class="list-group-item d-flex justify-content-between align-items-center">
Inbox
<span class="badge badge-primary badge-pill">12</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
Ads
<span class="badge badge-primary badge-pill">50</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
Junk
<span class="badge badge-primary badge-pill">99</span>
</li>
</ul>
亲自试一试 »
提示:阅读我们的 Bootstrap 4 Utility/Helper 类的更多信息BS4 公用事业章。