定制Twitter Bootstrap的轮播

时间:2012-06-28 07:07:01

标签: html css twitter twitter-bootstrap

关于在Twitter Bootstrrap中使用Carousel的问题

我是Twitter Bootstrap的新手。现在我想在我的页面中创建一个轮播。但我遇到了一些问题。

首先,我发现在css文件中没有位置可以将我的旋转木马放在中心位置。

其次,我不知道如何使宽度标题与旋转木马中的图像相同。

这是我的HTML代码:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Test</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Le styles -->
    <link href="rootfolder/bootstrap/docs/assets/css/bootstrap.css" rel="stylesheet">
    <link href="rootfolder/bootstrap/docs/assets/css/bootstrap-responsive.css" rel="stylesheet">
    <link href="rootfolder/bootstrap/docs/assets/css/docs.css" rel="stylesheet">
    <link href="rootfolder/bootstrap/docs/assets/js/google-code-prettify/prettify.css" rel="stylesheet">
    <link href="rootfolder/bootstrap/docs/assets/css/bootstrap-carousel.css" rel="stylesheet">
    <link href="rootfolder/css/temp.css" rel="stylesheet">

    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    <!-- Le fav and touch icons -->
    <link rel="shortcut icon" href="assets/ico/favicon.ico">
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">

    <script type="text/javascript">
      $(function () {  
        $('.dropdown-toggle').dropdown();  
      });
    </script>

    <!--Lightbox--> 
    <script type="text/javascript">
      $(function () {  
        $('.carousel').carousel('cycle') 
      });
    </script>
  </head>

  <body data-spy="scroll" data-target=".subnav" data-offset="50">

  <!-- Navbar
================================================== -->
    <div class="navbar navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <button type="button"class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
              </button>
              <a class="brand" href="http://about.me/nienyiho">Nien-Yi Ho</a>
              <div class="nav-collapse collapse">
                <ul class="nav">
              <li class="dropdown" id="accountmenu">  
                <a class="dropdown-toggle" data-toggle="dropdown" href="#">About<b class="caret"></b></a>  
                <ul class="dropdown-menu">  
                  <li><a href="#">About Me</a></li>  
                </ul>  
              </li>
              <li class="">
                <a href="http://www.nienyiho.com/photography.html">Photography</a>
              </li>
              <li class="">
                <a href="http://www.nienyiho.com/articles.html">Articles</a>
              </li>
              <li class="">
                <a href="http://www.nienyiho.com/forsale.html">For Sale</a>
              </li>
              <li class="">
                <a href="http://nienyi.blogspot.tw">Blog</a>
              </li>
              <li class="">
                <a href="http://nienyi.blogspot.tw">Contact</a>
              </li>
              <li class="dropdown" id="accountmenu">  
                <a class="dropdown-toggle" data-toggle="dropdown" href="#">Tutorials<b class="caret"></b></a>  
            <ul class="dropdown-menu">  
              <li><a href="#">1</a></li>  
              <li><a href="#">2</a></li>  
              <li class="divider"></li>  
              <li><a href="#">3</a></li>  
              <li><a href="#">4</a></li>  
            </ul>  
          </li>
        </ul>
      </div>
    </div>
  </div>
</div>

<div class="container">

<!-- Masthead
================================================== -->
<header class="jumbotron masthead">

  <div class="inner">
    <p>Nien-Yi Ho Photography</p>
  </div>
</header>

  <!--測試Light Box-->

  <div id="myCarousel" class="carousel slide">
  <!-- Carousel items -->
    <div class="carousel-inner_test">
      <div class="active item">
        <img src="rootfolder/images/photography/all_time_collections/1.jpg" alt="" width="600" hight="900">
        <div class="carousel-caption">
          <h4>何去何從</h4>
          <p>台北 2008</p>
        </div>
      </div>

      <div class="item">
        <img src="rootfolder/images/photography/all_time_collections/2.jpg" alt="" width="600" hight="900">
        <div class="carousel-caption">
          <h4>撼動</h4>
          <p>2008 台大合唱團冬季公演</p>
        </div>
      </div>

      <div class="item">
        <img src="rootfolder/images/photography/all_time_collections/3.jpg" alt="" width="600" hight="900">
        <div class="carousel-caption">
          <h4>Height of the sky.</h4>
          <p>Paris 2002</p>
        </div>
      </div>
    </div>
  <!-- Carousel nav -->
  <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
  <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;    </a>
  </div>

     <!-- Footer
  ================================================== -->
      <footer class="footer">
        <p>Powered by <a href="http://twitter.github.com/bootstrap/" target="_blank">Twitter Bootstrap</a> </p>
      </footer>

    </div><!-- /container -->

        <!-- Le javascript
================================================== -->
        <!-- Placed at the end of the document so the pages load faster -->
    <script type="text/javascript" src="http://platform.twitter.com/widgets.js">    </script>
    <script type="text/javascript" src="rootfolder/bootstrap/docs/assets/js/jquery.js"></script>
    <script type="text/javascript" src="rootfolder/bootstrap/docs/assets/js/google-code-prettify/prettify.js"></script>
    <script type="text/javascript" src="rootfolder/bootstrap/docs/assets/js/bootstrap-transition.js"></script>
    <script type="text/javascript" src="rootfolder/bootstrap/docs/assets/js/bootstrap-alert.js"></script>
    <script type="text/javascript" src="rootfolder/bootstrap/docs/assets/js/bootstrap-modal.js"></script>
    <script type="text/javascript" src="rootfolder/bootstrap/docs/assets/js/bootstrap-dropdown.js" type="text/javascript"></script>
    <script type="text/javascript" src="rootfolder/bootstrap/docs/assets/js/bootstrap-scrollspy.js"></script>
    <script type="text/javascript" src="rootfolder/bootstrap/docs/assets/js/bootstrap-tab.js"></script>
    <script type="text/javascript" src="rootfolder/bootstrap/docs/assets/js/bootstrap-tooltip.js"></script>
    <script type="text/javascript" src="rootfolder/bootstrap/docs/assets/js/bootstrap-popover.js"></script>
    <script type="text/javascript" src="rootfolder/bootstrap/docs/assets/js/bootstrap-button.js"></script>
    <script type="text/javascript" src="rootfolder/bootstrap/docs/assets/js/bootstrap-collapse.js"></script>
<script type="text/javascript" src="rootfolder/bootstrap/docs/assets/js/bootstrap-carousel.js"></script>
    <script type="text/javascript" src="rootfolder/bootstrap/docs/assets/js/bootstrap-typeahead.js"></script>
    <script type="text/javascript" src="rootfolder/bootstrap/docs/assets/js/application.js"></script>

  </body>
</html>

1 个答案:

答案 0 :(得分:2)

为了让旋转木马坐在中间你可以:

更改CSS类:

carousel-inner_test to just carousel-inner

然后添加到#myCarousel元素:

width: 600px;
margin: 0px auto;   

这也应该解决你的标题问题!

HTH