List group with badges - CSS: Cascading Style Sheets 编辑
In this recipe we will create a list group pattern with badges that indicate a count.
Requirements
Our list items should be displayed with the badges lined up on the right, no matter how much content the item has. The badge should always be centered vertically whether there is a single line of content, or more than one.
Recipe
Choices made
Flexbox makes this particular pattern straightforward and also makes it easy to make changes to the layout.
To ensure the text and badge line up correctly I use the justify-content
property with a value of space-between
. This places any extra space between the items. In the live example, if you remove this property and you will see the badge move to the end of the text on items with text shorter than the one line.
To align the content horizontally, I use the align-items
property to align the text and badge on the cross axis. If instead, you want the badge to align to the top of the content, change this to align-items: flex-start
.
Browser compatibility
The various layout methods have different browser support. See the charts below for details on basic support for the properties used.
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
justify-content
BCD tables only load in the browser
align-items
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论