Bootstrap 縮略圖

2021-10-15 13:47 更新

Bootstrap 縮略圖

本章將講解 Bootstrap 縮略圖。大多數(shù)站點都需要在網(wǎng)格中布局圖像、視頻、文本等。Bootstrap 通過縮略圖為此提供了一種簡便的方式。使用 Bootstrap 創(chuàng)建縮略圖的步驟如下:

  • 在圖像周圍添加帶有 class .thumbnail<a> 標簽。

  • 這會添加四個像素的內(nèi)邊距(padding)和一個灰色的邊框。

  • 當鼠標懸停在圖像上時,會動畫顯示出圖像的輪廓。

下面的實例演示了默認的縮略圖:

<!DOCTYPE html><html><head>
   <title>Bootstrap 實例 - 縮略圖</title>
   <link  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" ></script>
   <script src="http://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js" rel="external nofollow"  rel="external nofollow" ></script></head><body><div class="row">
   <div class="col-sm-6 col-md-3">
      <a href="#" class="thumbnail">
         <img src="/wp-content/uploads/2014/06/kittens.jpg" 
         alt="通用的占位符縮略圖">
      </a>
   </div>
   <div class="col-sm-6 col-md-3">
      <a href="#" class="thumbnail">
         <img src="/wp-content/uploads/2014/06/kittens.jpg" 
         alt="通用的占位符縮略圖">
      </a>
   </div>
   <div class="col-sm-6 col-md-3">
      <a href="#" class="thumbnail">
         <img src="/wp-content/uploads/2014/06/kittens.jpg" 
         alt="通用的占位符縮略圖">
      </a>
   </div>
   <div class="col-sm-6 col-md-3">
      <a href="#" class="thumbnail">
         <img src="/wp-content/uploads/2014/06/kittens.jpg" 
         alt="通用的占位符縮略圖">
      </a>
   </div></div></body></html>

結(jié)果如下所示:

縮略圖

添加自定義的內(nèi)容

現(xiàn)在我們有了一個基本的縮略圖,我們可以向縮略圖添加各種 HTML 內(nèi)容,比如標題、段落或按鈕。具體步驟如下:

  • 把帶有  class .thumbnail 的 <a> 標簽改為 <div>。

  • 在該 <div> 內(nèi),您可以添加任何您想要添加的東西。由于這是一個 <div>,我們可以使用默認的基于 span 的命名規(guī)則來調(diào)整大小。

  • 如果您想要給多個圖像進行分組,請把它們放置在一個無序列表中,且每個列表項向左浮動。

下面的實例演示了這點:

<!DOCTYPE html><html><head>
   <title>Bootstrap 實例 - 自定義縮略圖</title>
   <link  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" ></script>
   <script src="http://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js" rel="external nofollow"  rel="external nofollow" ></script></head><body><div class="row">
   <div class="col-sm-6 col-md-3">
      <div class="thumbnail">
         <img src="/wp-content/uploads/2014/06/kittens.jpg" 
         alt="通用的占位符縮略圖">
      </div>
      <div class="caption">
         <h3>縮略圖標簽</h3>
         <p>一些示例文本。一些示例文本。</p>
         <p>
            <a href="#" class="btn btn-primary" role="button">
               按鈕            </a> 
            <a href="#" class="btn btn-default" role="button">
               按鈕            </a>
         </p>
      </div>
   </div>
   <div class="col-sm-6 col-md-3">
      <div class="thumbnail">
         <img src="/wp-content/uploads/2014/06/kittens.jpg" 
         alt="通用的占位符縮略圖">
      </div>
      <div class="caption">
         <h3>縮略圖標簽</h3>
         <p>一些示例文本。一些示例文本。</p>
         <p>
            <a href="#" class="btn btn-primary" role="button">
               按鈕            </a> 
            <a href="#" class="btn btn-default" role="button">
               按鈕            </a>
         </p>
      </div>
   </div>
   <div class="col-sm-6 col-md-3">
      <div class="thumbnail">
         <img src="/wp-content/uploads/2014/06/kittens.jpg" 
         alt="通用的占位符縮略圖">
      </div>
      <div class="caption">
         <h3>縮略圖標簽</h3>
         <p>一些示例文本。一些示例文本。</p>
         <p>
            <a href="#" class="btn btn-primary" role="button">
               按鈕            </a> 
            <a href="#" class="btn btn-default" role="button">
               按鈕            </a>
         </p>
      </div>
   </div>
   <div class="col-sm-6 col-md-3">
      <div class="thumbnail">
         <img src="/wp-content/uploads/2014/06/kittens.jpg" 
         alt="通用的占位符縮略圖">
      </div>
      <div class="caption">
         <h3>縮略圖標簽</h3>
         <p>一些示例文本。一些示例文本。</p>
         <p>
            <a href="#" class="btn btn-primary" role="button">
               按鈕            </a> 
            <a href="#" class="btn btn-default" role="button">
               按鈕            </a>
         </p>
      </div>
   </div></div></body></html>

結(jié)果如下所示:

自定義縮略圖 
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號