简体   繁体   English

管理轮播指标的宽度

[英]Managing width of a carousel-indicators

I want to use custom carousel-indicators. 我想使用自定义轮播指标。 I want to use three divs for the indicators of col-md-4 class. 我想将三个div用于col-md-4类的指标。 My code is: 我的代码是:

<div class="row carousel-indicators">
            <div style="background-color:red;" class="col-md-4" data-target="#homeCarousel" data-slide-to="0" class="active">
                First
            </div>
            <div style="background-color:green;" class="col-md-4" data-target="#homeCarousel" data-slide-to="1">
                Second  
            </div>
            <div style="background-color:blue;" class="col-md-4" data-target="#homeCarousel" data-slide-to="2">
                Third
            </div>
        </div>

But, it is not working properly. 但是,它无法正常工作。 On clicking any of the tab, the div collapses. 单击任何选项卡时,div折叠。

图片截图在这里

Please help me to solve this. 请帮我解决这个问题。

Edit 1: 编辑1:

The full code is: 完整的代码是:

<div class="container-fluid">
    <div id="homeCarousel" class="carousel slide" data-ride="carousel">

        <div class="container">
            <div class="row carousel-indicators">
                <div style="background-color:red;" class="col-md-4" data-target="#homeCarousel" data-slide-to="0" class="active">
                    First
                </div>
                <div style="background-color:green;" class="col-md-4" data-target="#homeCarousel" data-slide-to="1">
                    Second  
                </div>
                <div style="background-color:blue;" class="col-md-4" data-target="#homeCarousel" data-slide-to="2">
                    Third
                </div>
            </div>

        </div>
        <!-- Wrapper for slides -->
        <div class="carousel-inner" role="listbox">
            <div class="item active">
                <img style="width:100%;height:90%;" src="https://www.google.com/logos/doodles/2014/world-cup-2014-51-5668472285560832.2-hp.gif">
                <div class="carousel-caption">

                </div>
            </div>
            <div class="item">
                <img style="width:100%;height:90%;" src="http://i.forbesimg.com/media/lists/companies/google_416x416.jpg">
                <div class="carousel-caption">

                </div>
            </div>
            <div class="item">
                <img style="width:100%;height:90%;" src="http://i.forbesimg.com/media/lists/companies/google_416x416.jpg">
                <div class="carousel-caption">

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

        <!-- Controls -->
        <a class="left carousel-control" href="#homeCarousel" role="button" data-slide="prev">
            <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
            <span class="sr-only">Previous</span>
        </a>
        <a class="right carousel-control" href="#homeCarousel" role="button" data-slide="next">
            <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
        </a>
    </div>
</div>

The problem was that the Carousel JS was appending the class of the buttons with active which overrides its width to 12px and height to 12px. 问题是,Carousel JS将具有active的按钮类附加到了按钮上,从而将其宽度改写为12px,将高度改写为12px。 Try the below code. 试试下面的代码。

.carousel-indicators .col-md-4.active {
  width: 33.33%;
  height: auto;
}

JSfiddle JS小提琴

You are close! 你近了! Since Bootstrap uses media queries, each particular class applies to a certain screen size. 由于Bootstrap使用媒体查询,因此每个特定的类都适用于特定的屏幕尺寸。 Relevant part of Bootstrap documentation: Bootstrap文档的相关部分:

http://getbootstrap.com/css/#grid-options http://getbootstrap.com/css/#grid-options

The above link describes behavior at each screen size. 上面的链接描述了每种屏幕尺寸下的行为。 In your code, you only specify the col-md-4 class; 在您的代码中,您仅指定col-md-4类。 by adding col-sm-4 col-lg-4 , you should cover all use cases. 通过添加col-sm-4 col-lg-4 ,您应该涵盖所有用例。

Updated Fiddle: http://jsfiddle.net/dmkzu8eL/2/ 更新的小提琴: http : //jsfiddle.net/dmkzu8eL/2/

EDIT: So, I misread the question initially. 编辑:所以,我最初看错了问题。 Essentially, the .active class is appended to the carousel indicator corresponding to the active item in the carousel. 本质上, .active类被附加到轮播指示器上,该指示器对应于轮播中的活动项目。 This class specifies a width, height, and margin in terms of px , which is why it appears to collapse. 此类以px为单位指定宽度,高度和边距,这就是为什么它看上去会塌陷的原因。 Using the following CSS, we can stop the div from collapsing fully and hiding the text within: 使用以下CSS,我们可以阻止div完全折叠并将文本隐藏在其中:

#homeCarousel .carousel-indicators div.active
{
width:initial;
height:initial;
margin:initial;
}

With that said, it doesn't stop the .active div from shrinking down to the size of the text contained within, as you still would like to indicate to the user the position of the carousel, correct? 话虽如此,它不会阻止.active div缩小到其中包含的文本的大小,因为您仍然想向用户指示转盘的位置,对吗?

Updated Fiddle #2: http://jsfiddle.net/dmkzu8eL/12/ 更新的小提琴#2: http : //jsfiddle.net/dmkzu8eL/12/

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

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