本章我們將講解列表組。列表組件用于以列表形式呈現(xiàn)復(fù)雜的和自定義的內(nèi)容。創(chuàng)建一個基本的列表組的步驟如下:
下面的實例演示了這點:
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 實例 - 基本的列表組</title>
<link rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="stylesheet">
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script>
<script src="http://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></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">圖像的數(shù)量</li>
<li class="list-group-item">24*7 支持</li>
<li class="list-group-item">每年更新成本</li>
</ul>
</body>
</html>
結(jié)果如下所示:
我們可以向任意的列表項添加徽章組件,它會自動定位到右邊。只需要在 <li> 元素中添加 <span class="badge"> 即可。下面的實例演示了這點:
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 實例 - 向列表組添加徽章</title>
<link rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="stylesheet">
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script>
<script src="http://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></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">圖像的數(shù)量</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>
折扣優(yōu)惠
</li>
</ul>
</body>
</html>
結(jié)果如下所示:
有關(guān)Bootstrap徽章的更多內(nèi)容,請參考“
Bootstrap 徽章”部分!通過使用錨標(biāo)簽代替列表項,我們可以向列表組添加鏈接。我們需要使用 <a> 代替 <ul> 元素。下面的實例演示了這點:
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 實例 - 向列表組添加鏈接</title>
<link rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="stylesheet">
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script>
<script src="http://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></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">圖像的數(shù)量</a>
<a href="#" class="list-group-item">每年更新成本</a>
</body>
</html>
結(jié)果如下所示:
我們可以向上面已添加鏈接的列表組添加任意的 HTML 內(nèi)容。下面的實例演示了這點:
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 實例 - 向列表組添加自定義內(nèi)容</title>
<link rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="stylesheet">
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script>
<script src="http://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script>
</head>
<body>
<div class="list-group">
<a href="#" class="list-group-item active">
<h4 class="list-group-item-heading">
入門網(wǎng)站包
</h4>
</a>
<a href="#" class="list-group-item">
<h4 class="list-group-item-heading">
免費域名注冊
</h4>
<p class="list-group-item-text">
您將通過網(wǎng)頁進(jìn)行免費域名注冊。
</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">
商務(wù)網(wǎng)站包
</h4>
</a>
<a href="#" class="list-group-item">
<h4 class="list-group-item-heading">
免費域名注冊
</h4>
<p class="list-group-item-text">
您將通過網(wǎng)頁進(jìn)行免費域名注冊。
</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>
結(jié)果如下所示:
上面實例中列表都是按垂直顯示的,如果我們需要一個水平列表,可以通過以下代碼實現(xiàn):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Bootstrap 實例 - 實現(xiàn)水平列表</title>
<link rel="stylesheet" rel="external nofollow" target="_blank" >
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js" rel="external nofollow" ></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js" rel="external nofollow" ></script>
<style>
.list-group-horizontal .list-group-item {
display: inline-block;
}
.list-group-horizontal .list-group-item {
margin-bottom: 0;
margin-left:-4px;
margin-right: 0;
}
.list-group-horizontal .list-group-item:first-child {
border-top-right-radius:0;
border-bottom-left-radius:4px;
}
.list-group-horizontal .list-group-item:last-child {
border-top-right-radius:4px;
border-bottom-left-radius:0;
}
</style>
</head>
<body>
<div class="container">
<div class="row" style="padding-top:50px">
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 text-center">
<div class="list-group list-group-horizontal">
<a href="#" class="list-group-item active">Google</a>
<a href="#" class="list-group-item">W3cschool</a>
<a href="#" class="list-group-item">Taobao</a>
<a href="#" class="list-group-item">Github</a>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 text-center">
<div class="list-group list-group-horizontal">
<a href="#" class="list-group-item">Google</a>
<a href="#" class="list-group-item active">W3cschool</a>
<a href="#" class="list-group-item">Taobao</a>
<a href="#" class="list-group-item">Github</a>
</div>
</div>
</div>
</div>
</body>
</html>
結(jié)果如下所示:
更多建議: