更改Twitter Bootstrap的Image Carousel的大小

时间:2017-05-30 10:38:32

标签: html css twitter-bootstrap-3

我有这段代码:

   <div class="col-sm-4">
        <div class="card">
            <div class="card-block">
                <div class="col-sm-4">
                    <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
                        <ol class="carousel-indicators">
                            <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
                            <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
                            <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
                        </ol>
                        <div class="carousel-inner" role="listbox">
                            <div class="carousel-item active">
                                <img class="d-block img-fluid"
                                     src="http://www.public-domain-photos.com/free-cliparts-4/computer/actions/ok.png"
                                     alt="First slide">
                            </div>
                            <div class="carousel-item">
                                <img class="d-block img-fluid" src="https://k36.kn3.net/CA1AEE661.jpg"
                                     alt="Second slide">
                            </div>
                            <div class="carousel-item">
                                <img class="d-block img-fluid"
                                     src="http://www.public-domain-photos.com/free-cliparts-4/computer/actions/ok.png"
                                     alt="Third slide">
                            </div>
                        </div>
                        <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button"
                           data-slide="prev">
                            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                            <span class="sr-only">Previous</span>
                        </a>
                        <a class="carousel-control-next" href="#carouselExampleIndicators" role="button"
                           data-slide="next">
                            <span class="carousel-control-next-icon" aria-hidden="true"></span>
                            <span class="sr-only">Next</span>
                        </a>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

我以这3张随机图片为例。他们的分辨率要大得多,但在我的项目中显示的相当小。

当我尝试创建自己的CSS类而不是col-sm-4时,轮播停止工作。

如何调整旋转木马的大小?

1 个答案:

答案 0 :(得分:1)

使用类carousel-item而不是使用类item,或者您可以同时使用它们。确保至少有item课程。

试试这种方式。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<div class="col-sm-4">
        <div class="card">
            <div class="card-block">
                <div class="col-sm-12">
                    <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
                        <ol class="carousel-indicators">
                            <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
                            <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
                            <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
                        </ol>
                        <div class="carousel-inner" role="listbox">
                            <div class="carousel-item item active">
                                <img class="d-block img-fluid" src="http://www.public-domain-photos.com/free-cliparts-4/computer/actions/ok.png" alt="First slide">
                            </div>
                            <div class="carousel-item item">
                                <img class="d-block img-fluid" src="https://k36.kn3.net/CA1AEE661.jpg" alt="Second slide">
                            </div>
                            <div class="carousel-item item">
                                <img class="d-block img-fluid" src="http://www.public-domain-photos.com/free-cliparts-4/computer/actions/ok.png" alt="Third slide">
                            </div>
                        </div>
                        <!-- Left and right controls -->
                        <a class="left carousel-control" href="#carouselExampleIndicators" data-slide="prev">
                            <span class="glyphicon glyphicon-chevron-left"></span>
                            <span class="sr-only">Previous</span>
                        </a>
                        <a class="right carousel-control" href="#carouselExampleIndicators" data-slide="next">
                            <span class="glyphicon glyphicon-chevron-right"></span>
                            <span class="sr-only">Next</span>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>