简体   繁体   English

设置图像轮播的高度,宽度

[英]Setting the height, width of image carousel

My Image carousel code as follows 我的图片轮播代码如下

<div class="container">
    <div class="row">
        <div class="col-md-12 col-md-offset-0">
            <div id="imageCarousel" class="carousel slide" data-interval="4000"
                 data-ride="carousel" data-pause="hover" data-wrap="true">

                <ol class="carousel-indicators">
                    <li data-target="#imageCarousel" data-slide-to="0" class="active"></li>
                    <li data-target="#imageCarousel" data-slide-to="1"></li>
                    <li data-target="#imageCarousel" data-slide-to="2"></li>
                    <li data-target="#imageCarousel" data-slide-to="3"></li>
                </ol>

                <div class="carousel-inner">
                    <div class="item active">
                        <img src="~/Images/Desert.jpg" class="img-responsive">
                        <div class="carousel-caption">
                            <h3>Desert</h3>
                            <p>Desert Image Description</p>
                        </div>
                    </div>
                    <div class="item">
                        <img src="~/Images/Jellyfish.jpg" class="img-responsive">
                        <div class="carousel-caption">
                            <h3>Jellyfish</h3>
                            <p>Jellyfish Image Description</p>
                        </div>
                    </div>
                    <div class="item">
                        <img src="~/Images/Lighthouse.jpg" class="img-responsive">
                        <div class="carousel-caption">
                            <h3>Lighthouse</h3>
                            <p>Lighthouse Image Description</p>
                        </div>
                    </div>
                    <div class="item">
                        <img src="~/Images/Penguins.jpg" class="img-responsive">
                        <div class="carousel-caption">
                            <h3>Penguins</h3>
                            <p>Penguins Image Description</p>
                        </div>
                    </div>
                </div>

                <a href="#imageCarousel" class="carousel-control left" data-slide="prev">
                    <span class="glyphicon glyphicon-chevron-left"></span>
                </a>
                <a href="#imageCarousel" class="carousel-control right" data-slide="next">
                    <span class="glyphicon glyphicon-chevron-right"></span>
                </a>
            </div>

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

And added the following jquery: 并添加了以下jquery:

<script src="~/Scripts/jquery-1.10.2.min.js"></script>

Finally I used following code to set the size of image carousel 最后,我使用以下代码来设置图像轮播的大小

<style>
.carousel-inner > .item > img {
 width: 1200px;
 height: 360px;
}
</style>

The problem is when the page loads, it loads with the given dimensions and then suddenly get large. 问题是页面加载时,页面会加载给定的尺寸,然后突然变大。 When I change the width to different number then the width is set as expected, but the size of the height is not set to given value. 当我将宽度更改为其他数字时,宽度将按预期设置,但高度的大小未设置为给定值。 When I reduce the width then the height also changes with the width. 当我减小宽度时,高度也会随着宽度而变化。 I implemented the code for new MVC simple web application and this works well as I expected. 我为新的MVC简单的Web应用程序实现了代码,并且效果很好。 But when I tried to implement the same for existing project, I got the problem of setting the height of the carousel. 但是,当我尝试对现有项目实施同样的操作时,我遇到了设置转盘高度的问题。

Could you please can any one give me an idea to get this issue solved. 您能否请任何一个给我一个主意以解决此问题。

Use !important rule to height property. 对高度属性使用!important规则。 !important rule overrides that particular property. !important规则将覆盖该特定属性。

 .carousel-inner > .item > img { width: 1200px; height: 360px !important; } 
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <div class="container"> <div class="row"> <div class="col-md-12 col-md-offset-0"> <div id="imageCarousel" class="carousel slide" data-interval="4000" data-ride="carousel" data-pause="hover" data-wrap="true"> <ol class="carousel-indicators"> <li data-target="#imageCarousel" data-slide-to="0" class="active"></li> <li data-target="#imageCarousel" data-slide-to="1"></li> <li data-target="#imageCarousel" data-slide-to="2"></li> <li data-target="#imageCarousel" data-slide-to="3"></li> </ol> <div class="carousel-inner"> <div class="item active"> <img src="~/Images/Desert.jpg" class="img-responsive"> <div class="carousel-caption"> <h3>Desert</h3> <p>Desert Image Description</p> </div> </div> <div class="item"> <img src="~/Images/Jellyfish.jpg" class="img-responsive"> <div class="carousel-caption"> <h3>Jellyfish</h3> <p>Jellyfish Image Description</p> </div> </div> <div class="item"> <img src="~/Images/Lighthouse.jpg" class="img-responsive"> <div class="carousel-caption"> <h3>Lighthouse</h3> <p>Lighthouse Image Description</p> </div> </div> <div class="item"> <img src="~/Images/Penguins.jpg" class="img-responsive"> <div class="carousel-caption"> <h3>Penguins</h3> <p>Penguins Image Description</p> </div> </div> </div> <a href="#imageCarousel" class="carousel-control left" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left"></span> </a> <a href="#imageCarousel" class="carousel-control right" data-slide="next"> <span class="glyphicon glyphicon-chevron-right"></span> </a> </div> </div> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM