Bootstrap一個小案例

風靈使發表於2018-08-17

index.html

<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3個meta標籤*必須*放在最前面,任何其他內容都*必須*跟隨其後! -->
    <title>index</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!--[if lt IE 9]>
      <script src="//cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
      body{ padding-top: 50px; padding-bottom: 50px; }

      /*輪播廣告*/
      .carousel{ height: 500px; margin-bottom: 60px;  }
      .carousel .item{ height: 500px; background-color: #000;  }
      .carousel .item img{ width: 100%;  }
      .carousel-caption{ z-index: 10;  }
      .carousel-caption p{ margin-bottom: 20px; font-size: 20px; line-height: 1.8;  }

      /*簡介*/
      .summary{ padding-left: 15px; padding-right: 15px;  }
      .summary .col-md-4 {
            margin-bottom: 20px;
            text-align: center;
        }

      hr.feature-divider{ margin: 40px 0;  }

      /*特性*/
      .feature{ padding: 30px 0; }
      .feature-heading{ font-size: 50px; color: #2a6496;  }
      .feature-heading .text-muted { font-size: 28px; }

      /* 響應式佈局 */

      @media (max-width: 768px) {

          .summary {
              padding-right: 3px;
              padding-left: 3px;
          }

          .carousel {
              height: 300px;
              margin-bottom: 30px;
          }

          .carousel .item {
              height: 300px;
          }

          .carousel img {
              min-height: 300px;
          }

          .carousel-caption p {
              font-size: 16px;
              line-height: 1.4;
          }

          .feature-heading {
              font-size: 34px;
          }

          .feature-heading .text-muted {
              font-size: 22px;
          }
      }


      @media (min-width: 992px) {
          .feature-heading {
              margin-top: 120px;
          }
      }

    </style>
  </head>
  <body>
    <!-- 導航條 -->
    <nav class="navbar navbar-inverse navbar-fixed-top" id="menu-nav">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">現代瀏覽器博物館</a>
        </div>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#ad-carousel">綜述</a></li>
            <li><a href="#summary-container">簡述</a></li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">特點<span class="caret"></span></a>
              <ul class="dropdown-menu">
                <li><a href="#feature-tab" data-tab="tab-chrome">Chrome</a></li>
                <li><a href="#feature-tab" data-tab="tab-firefox">Firefox</a></li>
                <li><a href="#feature-tab" data-tab="tab-safari">Safari</a></li>
                <li><a href="#feature-tab" data-tab="tab-opera">Opera</a></li>
                <li><a href="#feature-tab" data-tab="tab-ie">IE</a></li>
              </ul>
            </li>
            <li><a href="#" data-toggle="modal" data-target="#about">關於</a></li>
          </ul>
        </div>
      </div>
    </nav>

    <!-- 滾動圖片廣告——carousel外掛 -->
    <div class="carousel slide" id="ad-carousel" data-ride="carousel">
      <!-- Indicators -->
      <ol class="carousel-indicators">
        <li data-target="#ad-carousel" data-slide-to="0" class="active"></li>
        <li data-target="#ad-carousel" data-slide-to="1"></li>
        <li data-target="#ad-carousel" data-slide-to="2"></li>
        <li data-target="#ad-carousel" data-slide-to="3"></li>
        <li data-target="#ad-carousel" data-slide-to="4"></li>
      </ol>

      <!-- Wrapper for slides -->
      <div class="carousel-inner" role="listbox">
        <div class="item active">
          <img src="images/chrome-big.jpg" alt="1 slide">
          <div class="container">
            <div class="carousel-caption">
              <h1>Chrome</h1>
              <p>Google Chrome,又稱Google瀏覽器,是一個由Google(谷歌)公司開發的網頁瀏覽器。</p>
              <p><a class="btn btn-lg btn-primary" href="http://www.google.cn/intl/zh-CN/chrome/browser/"
                    role="button" target="_blank">點我下載</a></p>
            </div>
          </div>
        </div>

        <div class="item">
          <img src="images/firefox-big.jpg" alt="2 slide">
          <div class="container">
            <div class="carousel-caption">
              <h1>Firefox</h1>
              <p>Mozilla Firefox,中文名通常稱為“火狐”或“火狐瀏覽器”,是一個開源網頁瀏覽器。</p>
              <p><a class="btn btn-lg btn-primary" href="http://www.firefox.com.cn/download/" target="_blank"
                    role="button">點我下載</a></p>
            </div>
          </div>
        </div>

        <div class="item">
          <img src="images/safari-big.jpg" alt="3 slide">
          <div class="container">
            <div class="carousel-caption">
              <h1>Safari</h1>
              <p>Safari,是蘋果計算機的最新作業系統Mac OS X中的瀏覽器。</p>
              <p><a class="btn btn-lg btn-primary" href="http://www.apple.com/cn/safari/" target="_blank"
                    role="button">點我下載</a></p>
            </div>
          </div>
        </div>

        <div class="item">
          <img src="images/opera-big.jpg" alt="4 slide">
          <div class="container">
            <div class="carousel-caption">
              <h1>Opera</h1>
              <p>Opera瀏覽器,是一款挪威Opera Software ASA公司製作的支援多頁面標籤式瀏覽的網路瀏覽器。</p>
              <p><a class="btn btn-lg btn-primary" href="http://www.opera.com/zh-cn" target="_blank"
                    role="button">點我下載</a></p>
            </div>
          </div>
        </div>

        <div class="item">
          <img src="images/ie-big.jpg" alt="5 slide">
          <div class="container">
            <div class="carousel-caption">
              <h1>IE</h1>
              <p>Internet Explorer,簡稱 IE,是微軟公司推出的一款網頁瀏覽器。</p>
              <p><a class="btn btn-lg btn-primary" href="http://ie.microsoft.com/" target="_blank"
                    role="button">點我下載</a></p>
            </div>
          </div>
        </div>
      </div>

      <!-- Controls -->
      <a class="left carousel-control" href="#ad-carousel" role="button" data-slide="prev">
        <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
        <span class="sr-only">上一張</span>
      </a>
      <a class="right carousel-control" href="#ad-carousel" role="button" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
        <span class="sr-only">下一張</span>
      </a>
    </div>

    <div class="container summary">
      <!-- 簡介——三欄佈局 -->
      <div class="row" id="summary-container">
        <div class="col-md-4">
          <img class="img-circle" src="images/chrome-logo-small.jpg" alt="chrome">
          <h2>Chrome</h2>
          <p>Google Chrome,又稱Google瀏覽器,是一個由Google(谷歌)公司開發的網頁瀏覽器。</p>
          <p><a class="btn btn-default" href="#" role="button">點我下載</a></p>
        </div>
        <div class="col-md-4">
          <img class="img-circle" src="images/firefox-logo-small.jpg" alt="firefox">
          <h2>Firefox</h2>
          <p>Mozilla Firefox,中文名通常稱為“火狐”或“火狐瀏覽器”,是一個開源網頁瀏覽器。</p>
          <p><a class="btn btn-default" href="#" role="button">點我下載</a></p>
        </div>
        <div class="col-md-4">
          <img class="img-circle" src="images/safari-logo-small.jpg" alt="safari">
          <h2>Safari</h2>
          <p>Safari,是蘋果計算機的最新作業系統Mac OS X中的瀏覽器。</p>
          <p><a class="btn btn-default" href="#" role="button">點我下載</a></p>
        </div>
      </div>

      <hr class="feature-divider">

      <!-- 特性 -->
      <ul class="nav nav-tabs" role="tablist" id="feature-tab">
        <li class="active"><a href="#tab-chrome" role="tab" data-toggle="tab">Chrome</a></li>
        <li><a href="#tab-firefox" role="tab" data-toggle="tab">Firefox</a></li>
        <li><a href="#tab-safari" role="tab" data-toggle="tab">Safari</a></li>
        <li><a href="#tab-opera" role="tab" data-toggle="tab">Opera</a></li>
        <li><a href="#tab-ie" role="tab" data-toggle="tab">IE</a></li>
      </ul>
      <div class="tab-content">
        <div class="tab-pane active" id="tab-chrome">
            <div class="row feature">
                <div class="col-md-7">
                    <h2 class="feature-heading">Google Chrome <span
                            class="text-muted">使用最廣的瀏覽器</span></h2>
                    <p class="lead">Google Chrome,又稱Google瀏覽器,是一個由Google(谷歌)公司開發的網頁瀏覽器。
                        該瀏覽器是基於其他開源軟體所撰寫,包括WebKit,目標是提升穩定性、速度和安全性,並創造出簡單且有效率的使用者介面。</p>
                </div>
                <div class="col-md-5">
                    <img class="feature-image img-responsive" src="images/chrome-logo.jpg"
                         alt="Chrome">
                </div>
            </div>
        </div>
        <div class="tab-pane" id="tab-firefox">
            <div class="row feature">
                <div class="col-md-5">
                    <img class="feature-image img-responsive" src="images/firefox-logo.jpg"
                         alt="Firefox">
                </div>
                <div class="col-md-7">
                    <h2 class="feature-heading">Mozilla Firefox <span class="text-muted">美麗的狐狸</span>
                    </h2>
                    <p class="lead">Mozilla Firefox,中文名通常稱為“火狐”或“火狐瀏覽器”,是一個開源網頁瀏覽器,
                        使用Gecko引擎(非ie核心),支援多種作業系統如Windows、Mac和linux。</p>
                </div>
            </div>
        </div>
        <div class="tab-pane" id="tab-safari">
            <div class="row feature">
                <div class="col-md-7">
                    <h2 class="feature-heading">Safari <span class="text-muted">Mac使用者首選</span></h2>
                    <p class="lead">Safari,是蘋果計算機的最新作業系統Mac OS X中的瀏覽器,使用了KDE的KHTML作為瀏覽器的運算核心。
                        Safari在2003年1月7日首度發行測試版,併成為Mac OS X v10.3與之後的預設瀏覽器,也是iPhone與IPAD和iPod touch的指定瀏覽器。</p>
                </div>
                <div class="col-md-5">
                    <img class="feature-image img-responsive" src="images/safari-logo.jpg"
                         alt="Safari">
                </div>
            </div>
        </div>
        <div class="tab-pane" id="tab-opera">
            <div class="row feature">
                <div class="col-md-5">
                    <img class="feature-image img-responsive" src="images/opera-logo.jpg"
                         alt="Opera">
                </div>
                <div class="col-md-7">
                    <h2 class="feature-heading">Opera <span class="text-muted">小眾但易用</span>
                    </h2>
                    <p class="lead">Opera瀏覽器,是一款挪威Opera Software ASA公司製作的支援多頁面標籤式瀏覽的網路瀏覽器。
                        是跨平臺瀏覽器可以在Windows、Mac和Linux三個作業系統平臺上執行。.</p>
                </div>
            </div>
        </div>
        <div class="tab-pane" id="tab-ie">
            <div class="row feature">
                <div class="col-md-7">
                    <h2 class="feature-heading">IE <span class="text-muted">你懂的</span></h2>
                    <p class="lead">Internet Explorer,原稱Microsoft Internet Explorer(6版本以前)和Windows Internet
                        Explorer(7,8,9,10版本),
                        簡稱IE,是美國微軟公司推出的一款網頁瀏覽器。它採用的排版引擎(俗稱核心)為Trident。</p>
                </div>
                <div class="col-md-5">
                    <img class="feature-image img-responsive" src="images/ie-logo.jpg"
                         alt="IE">
                </div>
            </div>
        </div>
      </div>

      <hr class="feature-divider">
      <footer>
        <p class="pull-right"><a href="#top">回到頂部</a></p>
        <p>© 2018</p>
      </footer>

    </div>

    <!-- 模態框 -->
    <div class="modal fade" id="about">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">關於</h4>
          </div>
          <div class="modal-body">
            <p>Bootstrap 提供了全面、美觀的文件。你能在這裡找到關於 HTML 元素、HTML 和 CSS 元件、jQuery 外掛方面的所有詳細文件。</p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">知道了</button>
          </div>
        </div><!-- /.modal-content -->
      </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->

    <script src="js/jquery-1.11.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script>
        $(function () {
            $('#ad-carousel').carousel();
            $('#menu-nav .navbar-collapse a').click(function (e) {
                var href = $(this).attr('href');  //feature-tab
                var tabId = $(this).attr('data-tab'); //tab-chrome、tab-firefox...
                if ('#' !== href) {
                    e.preventDefault();
                    $(document).scrollTop($(href).offset().top - 70); //滾出導航條覆蓋的範圍
                    if (tabId) {
                        $('#feature-tab a[href=#' + tabId + ']').tab('show'); //展示相應內容
                    }
                }
            });
        });
    </script>
  </body>
</html>

執行效果:

這裡寫圖片描述

這裡寫圖片描述

這裡寫圖片描述

程式碼下載地址

相關文章