Make Bootstrap's Carousel both center AND responsive?

后端 未结 13 2190
北海茫月
北海茫月 2020-12-05 02:45

I want my carousel images to be at the center (horizontally), which is not by default. I follow the solution at this topic.

However, using this solution, when the ca

相关标签:
13条回答
  • 2020-12-05 02:53

    add this

    .carousel .item img {
       left: -9999px;  /*important */
       right: -9999px;  /*important */
       margin: 0 auto;  /*important */
       max-width: none;  /*important */
       min-width: 100%;
       position: absolute;
    }
    

    And of course one of the parent divs needs to have a position:relative, but I believe it does by default.

    See it here: http://paginacrestinului.ro/

    0 讨论(0)
  • 2020-12-05 02:54

    On Boostrap 4 simply add mx-auto to your carousel image class.

    <div class="carousel-item">
      <img class="d-block mx-auto" src="http://placehold.it/600x400" />
    </div> 
    

    Combine with the samples from the bootstrap carousel documentation as desired.

    0 讨论(0)
  • 2020-12-05 02:56

    I've placed the <div class="carousel" id...> inside another div with the class container (<div class="container"><div class="carousel" id="my-carousel">...</div></div>). That solved it too.

    0 讨论(0)
  • 2020-12-05 02:59

    Now (on Boostrap 3 and 4) its simply :

    .carousel-inner img {
      margin: auto;
    }
    
    0 讨论(0)
  • 2020-12-05 03:01

    By using this on bootstrap 3:

    #carousel-example-generic{
        margin:auto;
    }
    
    0 讨论(0)
  • 2020-12-05 03:02

    Add a class to each image in the carousel html code, then with css apply margin: 0 auto.

    0 讨论(0)
提交回复
热议问题