Bootstrap list group


In this chapter we will explain list groups. The list component is used to present complex and custom content in the form of a list. The steps to create a basic list group are as follows:

  • Add class .list-group to the element <ul>.

  • Add class .list-group-item to <li>.

The following example demonstrates this:

Example

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap 实例 - 基本的列表组</title>
	<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
	<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<ul class="list-group">
	<li class="list-group-item">免费域名注册</li>
	<li class="list-group-item">免费 Window 空间托管</li>
	<li class="list-group-item">图像的数量</li>
	<li class="list-group-item">24*7 支持</li>
	<li class="list-group-item">每年更新成本</li>
</ul>


</body>
</html>

Running Example»

Click the "Run Instance" button to view the online instance

Add a badge to the list group

We can add a badge component to any list item, and it will automatically locate right. Just add <span class="badge"> to the <li> element. The following example demonstrates this:

Instance

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap 实例 - 向列表组添加徽章</title>
	<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
	<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<ul class="list-group">
	<li class="list-group-item">免费域名注册</li>
	<li class="list-group-item">免费 Window 空间托管</li>
	<li class="list-group-item">图像的数量</li>
	<li class="list-group-item">
		<span class="badge">新</span>
		24*7 支持
	</li>
	<li class="list-group-item">每年更新成本</li>
	<li class="list-group-item">
		<span class="badge">新</span>
		折扣优惠
	</li>
</ul>


</body>
</html>

Run Instance»

Click the "Run Instance" button to view Online Example

Add links to list groups

We can add links to list groups by using anchor tags instead of list items. We need to use <div> instead of <ul> element. The following example demonstrates this:

The result looks like this:

Example

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap 实例 - 向列表组添加链接</title>
	<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
	<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<a href="#" class="list-group-item active">
	免费域名注册
</a>
<a href="#" class="list-group-item">24*7 支持</a>
<a href="#" class="list-group-item">免费 Window 空间托管</a>
<a href="#" class="list-group-item">图像的数量</a>
<a href="#" class="list-group-item">每年更新成本</a>


</body>
</html>

Running Example»

Click the "Run Instance" button to view the online instance

Add custom content to the list group

We can add any HTML content to the list group that has been linked above . The following example demonstrates this:

Instance

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap 实例 - 向列表组添加自定义内容</title>
	<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
	<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="list-group">
	<a href="#" class="list-group-item active">
		<h4 class="list-group-item-heading">
			入门网站包
		</h4>
	</a>
	<a href="#" class="list-group-item">
		<h4 class="list-group-item-heading">
			免费域名注册
		</h4>
		<p class="list-group-item-text">
			您将通过网页进行免费域名注册。
		</p>
	</a>
	<a href="#" class="list-group-item">
		<h4 class="list-group-item-heading">
			24*7 支持
		</h4>
		<p class="list-group-item-text">
			我们提供 24*7 支持。
		</p>
	</a>
</div>
<div class="list-group">
	<a href="#" class="list-group-item active">
		<h4 class="list-group-item-heading">
			商务网站包
		</h4>
	</a>
	<a href="#" class="list-group-item">
		<h4 class="list-group-item-heading">
			免费域名注册
		</h4>
		<p class="list-group-item-text">
			您将通过网页进行免费域名注册。
		</p>
	</a>
	<a href="#" class="list-group-item">
		<h4 class="list-group-item-heading">24*7 支持</h4>
		<p class="list-group-item-text">我们提供 24*7 支持。</p>
	</a>
</div>

</body>
</html>

Run Instance»

Click the "Run Instance" button to view Online example