如何创建一个带有旋转木马底部缩略图和右侧旋转木马标题的自举旋转木马

时间:2014-09-09 18:18:42

标签: html css html5 css3 twitter-bootstrap-3

我正在使用Bootstrap 3x创建一个bootstrap轮播。我想为Big图像设置2个div(col-md-9),为显示相应的轮播标题设置另一个(col-md-3)。我想在底部有缩略图(col-md-12)。

目前,我能够显示带有缩略图的轮播,但是当我尝试为旋转木马的标题添加div时,它不适合我想要的。

我的当前代码

<div class="container"> 
<div class ="row">
    <!--Carousel-->
 <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <div id="carousel" class="carousel slide" data-ride="carousel">
            <div class="carousel-inner ">

                <div class="item active ">


                    <img class="image" src="img/construction.JPG">


                </div><!-- /item --> 

                <div class="item">

                    <img class="image" src="img/scaffolding.JPG">

                </div>

                <div class="item">

                    <img class="image" src="img/construction-iron.JPG">

                </div>

                <div class="item">

                    <img class="image" src="img/Bridge-Construction-Swale-Bridge.JPG">

                </div>

                <div class="item">

                    <img class="image" src="img/industrial-building-construction-scaffolding.JPG">

                </div>

                <div class="item">

                    <img class="image" src="img/men-at-building-construction.JPG">

                </div>

                <div class="item">

                    <img class="image" src="img/Construction-Workers.JPG">

                </div>

                <div class="item">

                    <img class="image" src="img/building-construction.JPG">

                </div>



            </div>
        </div>
    </div> <!-- /col-sm-6 -->
</div>
<div class ="row">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> 
    <div class="clearfix">
        <div id="thumbcarousel" class="carousel slide" data-interval="false">
            <div class="carousel-inner">
                <div class="item active">
                    <div data-target="#carousel" data-slide-to="0" class="thumb"><img src="img/construction.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="1" class="thumb"><img src="img/scaffolding.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="2" class="thumb"><img src="img/construction-iron.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="3" class="thumb"><img src="img/Bridge-Construction-Swale-Bridge.JPG" width="100" height="100"></div>
                </div><!-- /item -->
                <div class="item">
                    <div data-target="#carousel" data-slide-to="4" class="thumb"><img src="img/industrial-building-construction-scaffolding.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="5" class="thumb"><img src="img/men-at-building-construction.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="6" class="thumb"><img src="img/Construction-Workers.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="7" class="thumb"><img src="img/building-construction.JPG" width="100" height="100"></div>
                </div><!-- /item -->
            </div><!-- /carousel-inner -->
            <a class="left carousel-control" href="#thumbcarousel" role="button" data-slide="prev">
                <span class="glyphicon glyphicon-chevron-left"></span>
            </a>
            <a class="right carousel-control" href="#thumbcarousel" role="button" data-slide="next">
                <span class="glyphicon glyphicon-chevron-right"></span>
            </a>
        </div> <!-- /thumbcarousel -->
    </div><!-- /clearfix -->
    </div> <!-- /col-sm-6 -->
</div>  

    <!-- /.carousel -->

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

使用标题尝试1 以下问题是标题的文字没有出现

<div class="container"> 
<div class ="row">
    <!--Carousel-->
 <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <div id="carousel" class="carousel slide" data-ride="carousel">
            <div class="carousel-inner ">

                <div class="item active">

                <div class ="col-xs-12 col-sm-12 col-md-9 col-lg-9">
                    <img class="image" src="img/construction.JPG">
                </div><!-- /col-xs-9 col-sm-9 col-md-9 col-lg-9 -->
                <div class ="col-xs-12 col-sm-12 col-md-3 col-lg-3">
                    <div class="carousel-caption">
                        <h1>Welcome to our site! 5a4UkoC9vURkjKVHTBAgi7</h1>
                        <p>Take a look around and let us know if you have any questions.</p>
                    </div><!-- carousal-caption -->

                </div><!-- /col-xs-3 col-sm-3 col-md-3 col-lg-3 -->  

                </div><!-- /item --> 

                <div class="item">
                <div class ="col-xs-12 col-sm-12 col-md-9 col-lg-9">
                    <img class="image" src="img/scaffolding.JPG">
                </div><!-- /col-xs-9 col-sm-9 col-md-9 col-lg-9 -->

                </div>

                <div class="item">
                    <div class ="col-xs-12 col-sm-12 col-md-9 col-lg-9">
                    <img class="image" src="img/construction-iron.JPG">
                    </div><!-- /col-xs-9 col-sm-9 col-md-9 col-lg-9 -->  

                </div>

                <div class="item">
                <div class ="col-xs-12 col-sm-12 col-md-9 col-lg-9">
                    <img class="image" src="img/Bridge-Construction-Swale-Bridge.JPG">
                 </div><!-- /col-xs-9 col-sm-9 col-md-9 col-lg-9 -->

                </div>

                <div class="item">
                <div class ="col-xs-12 col-sm-12 col-md-9 col-lg-9">
                    <img class="image" src="img/industrial-building-construction-scaffolding.JPG">
                </div><!-- /col-xs-9 col-sm-9 col-md-9 col-lg-9 -->

                </div>

                <div class="item">
                <div class ="col-xs-12 col-sm-12 col-md-9 col-lg-9">
                    <img class="image" src="img/men-at-building-construction.JPG">
                </div><!-- /col-xs-9 col-sm-9 col-md-9 col-lg-9 -->

                </div>

                <div class="item">
                <div class ="col-xs-12 col-sm-12 col-md-9 col-lg-9">
                    <img class="image" src="img/Construction-Workers.JPG">
                </div><!-- /col-xs-9 col-sm-9 col-md-9 col-lg-9 -->

                </div>

                <div class="item">
                <div class ="col-xs-12 col-sm-12 col-md-9 col-lg-9">
                    <img class="image" src="img/building-construction.JPG">
                </div><!-- /col-xs-9 col-sm-9 col-md-9 col-lg-9 -->

                </div>



            </div>
        </div>
    </div> <!-- /col-sm-6 -->
</div>
<div class ="row">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> 
    <div class="clearfix">
        <div id="thumbcarousel" class="carousel slide" data-interval="false">
            <div class="carousel-inner">
                <div class="item active">
                    <div data-target="#carousel" data-slide-to="0" class="thumb"><img src="img/construction.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="1" class="thumb"><img src="img/scaffolding.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="2" class="thumb"><img src="img/construction-iron.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="3" class="thumb"><img src="img/Bridge-Construction-Swale-Bridge.JPG" width="100" height="100"></div>
                </div><!-- /item -->
                <div class="item">
                    <div data-target="#carousel" data-slide-to="4" class="thumb"><img src="img/industrial-building-construction-scaffolding.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="5" class="thumb"><img src="img/men-at-building-construction.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="6" class="thumb"><img src="img/Construction-Workers.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="7" class="thumb"><img src="img/building-construction.JPG" width="100" height="100"></div>
                </div><!-- /item -->
            </div><!-- /carousel-inner -->
            <a class="left carousel-control" href="#thumbcarousel" role="button" data-slide="prev">
                <span class="glyphicon glyphicon-chevron-left"></span>
            </a>
            <a class="right carousel-control" href="#thumbcarousel" role="button" data-slide="next">
                <span class="glyphicon glyphicon-chevron-right"></span>
            </a>
        </div> <!-- /thumbcarousel -->
    </div><!-- /clearfix -->
    </div> <!-- /col-sm-6 -->
</div>  

    <!-- /.carousel -->

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

使用标题尝试2

以下问题是标题的文字没有出现在大屏幕上,并且当浏览器较小时出现在大图像div上

<div class="container"> 
<div class ="row">
    <!--Carousel-->
 <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <div id="carousel" class="carousel slide" data-ride="carousel">
            <div class="carousel-inner ">

                <div class="item active ">

                <div class ="col-xs-12 col-sm-12 col-md-9 col-lg-9">
                    <img class="image" src="img/construction.JPG">
                </div><!-- /col-xs-9 col-sm-9 col-md-9 col-lg-9 -->

                <div class ="col-xs-12 col-sm-12 col-md-3 col-lg-3">
                    <div class="carousel-caption">
                        <h1>Welcome to our site! 5a4UkoC9vURkjKVHTBAgi7</h1>
                        <p>Take a look around and let us know if you have any questions.</p>
                    </div><!-- carousal-caption -->

                </div><!-- /col-xs-3 col-sm-3 col-md-3 col-lg-3 -->  
                </div><!-- /item --> 

                <div class="item">
                <div class ="col-xs-12 col-sm-12 col-md-9 col-lg-9">
                    <img class="image" src="img/scaffolding.JPG">
                </div><!-- /col-xs-9 col-sm-9 col-md-9 col-lg-9 -->
                <div class ="col-xs-12 col-sm-12 col-md-3 col-lg-3">
                    <div class="carousel-caption">
                        <h1>Welcome to our site2!</h1>
                        <p>Take a look around and let us know if you have any questions.</p>
                    </div><!-- carousal-caption -->

                </div><!-- /col-xs-3 col-sm-3 col-md-3 col-lg-3 -->  
                </div>

                <div class="item">
                    <div class ="col-xs-12 col-sm-12 col-md-9 col-lg-9">
                    <img class="image" src="img/construction-iron.JPG">
                    </div><!-- /col-xs-9 col-sm-9 col-md-9 col-lg-9 -->  
                    <div class ="col-xs-12 col-sm-12 col-md-3 col-lg-3">
                    <div class="carousel-caption">
                        <h1>Welcome to our site!</h1>
                        <p>Take a look around and let us know if you have any questions.</p>
                    </div><!-- carousal-caption -->

                </div><!-- /col-xs-3 col-sm-3 col-md-3 col-lg-3 -->  
                </div>

                <div class="item">
                <div class ="col-xs-12 col-sm-12 col-md-9 col-lg-9">
                    <img class="image" src="img/Bridge-Construction-Swale-Bridge.JPG">
                 </div><!-- /col-xs-9 col-sm-9 col-md-9 col-lg-9 -->
                <div class ="col-xs-12 col-sm-12 col-md-3 col-lg-3">
                    <div class="carousel-caption">
                        <h1>Welcome to our site!</h1>
                        <p>Take a look around and let us know if you have any questions.</p>
                    </div><!-- carousal-caption -->

                </div><!-- /col-xs-3 col-sm-3 col-md-3 col-lg-3 -->    
                </div>

                <div class="item">
                <div class ="col-xs-12 col-sm-12 col-md-9 col-lg-9">
                    <img class="image" src="img/industrial-building-construction-scaffolding.JPG">
                </div><!-- /col-xs-9 col-sm-9 col-md-9 col-lg-9 -->
                <div class ="col-xs-12 col-sm-12 col-md-3 col-lg-3">
                    <div class="carousel-caption">
                        <h1>Welcome to our site!</h1>
                        <p>Take a look around and let us know if you have any questions.</p>
                    </div><!-- carousal-caption -->

                </div><!-- /col-xs-3 col-sm-3 col-md-3 col-lg-3 -->     
                </div>

                <div class="item">
                <div class ="col-xs-12 col-sm-12 col-md-9 col-lg-9">
                    <img class="image" src="img/men-at-building-construction.JPG">
                </div><!-- /col-xs-9 col-sm-9 col-md-9 col-lg-9 -->
                <div class ="col-xs-12 col-sm-12 col-md-3 col-lg-3">
                    <div class="carousel-caption">
                        <h1>Welcome to our site!</h1>
                        <p>Take a look around and let us know if you have any questions.</p>
                    </div><!-- carousal-caption -->

                </div><!-- /col-xs-3 col-sm-3 col-md-3 col-lg-3 -->  
                </div>

                <div class="item">
                <div class ="col-xs-12 col-sm-12 col-md-9 col-lg-9">
                    <img class="image" src="img/Construction-Workers.JPG">
                </div><!-- /col-xs-9 col-sm-9 col-md-9 col-lg-9 -->
                <div class ="col-xs-12 col-sm-12 col-md-3 col-lg-3">
                    <div class="carousel-caption">
                        <h1>Welcome to our site!</h1>
                        <p>Take a look around and let us know if you have any questions.</p>
                    </div><!-- carousal-caption -->

                </div><!-- /col-xs-3 col-sm-3 col-md-3 col-lg-3 -->  
                </div>

                <div class="item">
                <div class ="col-xs-12 col-sm-12 col-md-9 col-lg-9">
                    <img class="image" src="img/building-construction.JPG">
                </div><!-- /col-xs-9 col-sm-9 col-md-9 col-lg-9 -->
                <div class ="col-xs-12 col-sm-12 col-md-3 col-lg-3">
                    <div class="carousel-caption">
                        <h1>Welcome to our site!</h1>
                        <p>Take a look around and let us know if you have any questions.</p>
                    </div><!-- carousal-caption -->

                </div><!-- /col-xs-3 col-sm-3 col-md-3 col-lg-3 -->  
                </div>



            </div>
        </div>
    </div> <!-- /col-sm-6 -->
</div>
<div class ="row">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> 
    <div class="clearfix">
        <div id="thumbcarousel" class="carousel slide" data-interval="false">
            <div class="carousel-inner">
                <div class="item active">
                    <div data-target="#carousel" data-slide-to="0" class="thumb"><img src="img/construction.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="1" class="thumb"><img src="img/scaffolding.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="2" class="thumb"><img src="img/construction-iron.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="3" class="thumb"><img src="img/Bridge-Construction-Swale-Bridge.JPG" width="100" height="100"></div>
                </div><!-- /item -->
                <div class="item">
                    <div data-target="#carousel" data-slide-to="4" class="thumb"><img src="img/industrial-building-construction-scaffolding.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="5" class="thumb"><img src="img/men-at-building-construction.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="6" class="thumb"><img src="img/Construction-Workers.JPG" width="100" height="100"></div>
                    <div data-target="#carousel" data-slide-to="7" class="thumb"><img src="img/building-construction.JPG" width="100" height="100"></div>
                </div><!-- /item -->
            </div><!-- /carousel-inner -->
            <a class="left carousel-control" href="#thumbcarousel" role="button" data-slide="prev">
                <span class="glyphicon glyphicon-chevron-left"></span>
            </a>
            <a class="right carousel-control" href="#thumbcarousel" role="button" data-slide="next">
                <span class="glyphicon glyphicon-chevron-right"></span>
            </a>
        </div> <!-- /thumbcarousel -->
    </div><!-- /clearfix -->
    </div> <!-- /col-sm-6 -->
</div>  

    <!-- /.carousel -->

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

1 个答案:

答案 0 :(得分:1)

我从我给你的the example做了一个分叉。

HTML:

<div class="container">
        <div id="main_area">
                <!-- Slider -->
                <div class="row">
                    <div class="col-xs-12" id="slider">
                        <!-- Top part of the slider -->
                        <div class="row">
                            <div class="col-sm-8" id="carousel-bounding-box">
                                <div class="carousel slide" id="myCarousel">
                                    <!-- Carousel items -->
                                    <div class="carousel-inner">
                                        <div class="active item" data-slide-number="0">
                                        <img src="http://placehold.it/770x300&amp;text=one"></div>

                                        <div class="item" data-slide-number="1">
                                        <img src="http://placehold.it/770x300&amp;text=two"></div>

                                        <div class="item" data-slide-number="2">
                                        <img src="http://placehold.it/770x300&amp;text=three"></div>

                                        <div class="item" data-slide-number="3">
                                        <img src="http://placehold.it/770x300&amp;text=four"></div>

                                        <div class="item" data-slide-number="4">
                                        <img src="http://placehold.it/770x300&amp;text=five"></div>

                                        <div class="item" data-slide-number="5">
                                        <img src="http://placehold.it/770x300&amp;text=six"></div>
                                    </div><!-- Carousel nav -->
                                    <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
                                        <span class="glyphicon glyphicon-chevron-left"></span>                                       
                                    </a>
                                    <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
                                        <span class="glyphicon glyphicon-chevron-right"></span>                                       
                                    </a>                                
                                    </div>
                            </div>

                            <div class="col-sm-4" id="carousel-text"></div>

                            <div id="slide-content" style="display: none;">
                                <div id="slide-content-0">
                                    <h2>Slider One</h2>
                                    <p>Lorem Ipsum Dolor</p>
                                    <p class="sub-text">October 24 2012 - <a href="#">Read more</a></p>
                                </div>

                                <div id="slide-content-1">
                                    <h2>Slider Two</h2>
                                    <p>Lorem Ipsum Dolor</p>
                                    <p class="sub-text">October 24 2012 - <a href="#">Read more</a></p>
                                </div>

                                <div id="slide-content-2">
                                    <h2>Slider Three</h2>
                                    <p>Lorem Ipsum Dolor</p>
                                    <p class="sub-text">October 24 2012 - <a href="#">Read more</a></p>
                                </div>

                                <div id="slide-content-3">
                                    <h2>Slider Four</h2>
                                    <p>Lorem Ipsum Dolor</p>
                                    <p class="sub-text">October 24 2012 - <a href="#">Read more</a></p>
                                </div>

                                <div id="slide-content-4">
                                    <h2>Slider Five</h2>
                                    <p>Lorem Ipsum Dolor</p>
                                    <p class="sub-text">October 24 2012 - <a href="#">Read more</a></p>
                                </div>

                                <div id="slide-content-5">
                                    <h2>Slider Six</h2>
                                    <p>Lorem Ipsum Dolor</p>
                                    <p class="sub-text">October 24 2012 - <a href="#">Read more</a></p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div><!--/Slider-->

                <div class="row hidden-xs" id="slider-thumbs">
                        <!-- Bottom switcher of slider -->
                        <ul class="hide-bullets">
                            <li class="col-sm-2">
                                <a class="thumbnail" id="carousel-selector-0"><img src="http://placehold.it/170x100&amp;text=one"></a>
                            </li>

                            <li class="col-sm-2">
                                <a class="thumbnail" id="carousel-selector-1"><img src="http://placehold.it/170x100&amp;text=two"></a>
                            </li>

                            <li class="col-sm-2">
                                <a class="thumbnail" id="carousel-selector-2"><img src="http://placehold.it/170x100&amp;text=three"></a>
                            </li>

                            <li class="col-sm-2">
                                <a class="thumbnail" id="carousel-selector-3"><img src="http://placehold.it/170x100&amp;text=four"></a>
                            </li>

                            <li class="col-sm-2">
                                <a class="thumbnail" id="carousel-selector-4"><img src="http://placehold.it/170x100&amp;text=five"></a>
                            </li>

                            <li class="col-sm-2">
                                <a class="thumbnail" id="carousel-selector-5"><img src="http://placehold.it/170x100&amp;text=six"></a>
                            </li>
                        </ul>                 
                </div>
        </div>
</div>

CSS:

.hide-bullets {
list-style:none;
margin-left: -40px;
margin-top:20px;
}

JS:

  jQuery(document).ready(function($) {

        $('#myCarousel').carousel({
                interval: 5000
        });

        $('#carousel-text').html($('#slide-content-0').html());

        //Handles the carousel thumbnails
        $('[id^=carousel-selector-]').click( function(){
                var id_selector = $(this).attr("id");
                var id = id_selector.substr(id_selector.length -1);
                var id = parseInt(id);
                $('#myCarousel').carousel(id);
        });


        // When the carousel slides, auto update the text
        $('#myCarousel').on('slid.bs.carousel', function (e) {
                 var id = $('.item.active').data('slide-number');
                $('#carousel-text').html($('#slide-content-'+id).html());
        });
});

功能性Bootply:http://www.bootply.com/zaKtDsH6V4