如何创建:带徽章的列表组
学习如何使用 CSS 创建带有徽章的列表组。
带徽章的列表组
- Inbox 2
- Other 5
- Saved
- Stuff
- Old
如何创建列表组
第一步 - 添加 HTML:
<ul> <li>Inbox <span class="badge">2</span></li> <li>Other <span class="badge">5</span></li> <li>Saved</li> <li>Stuff</li> <li>Old</li> </ul>
第二步 - 添加 CSS:
/* 将基本列表转换为自定义列表组 */
ul.list-group {
list-style-type: none;
padding: 0;
margin: 0;
}
ul.list-group li {
border: 1px solid #ddd;
margin-top: -1px; /* 防止双边框 */
background-color: #f6f6f6;
padding: 12px;
}
/* 设置列表组内徽章的样式 */
ul.list-group .badge {
background-color: red;
color: #fff;
font-weight: bold;
border-radius: 50%;
padding: 5px 10px;
text-align: center;
margin-left: 5px;
}
相关页面
教程:CSS 列表