Make Bootstrap's Carousel both center AND responsive?

后端 未结 13 2267
北海茫月
北海茫月 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 03:04

    I assume you have different sized images. I tested this myself, and it works as you describe (always centered, images widths appropriately)

    /*CSS*/
    div.c-wrapper{
        width: 80%; /* for example */
        margin: auto;
    }
    
    .carousel-inner > .item > img, 
    .carousel-inner > .item > a > img{
    width: 100%; /* use this, or not */
    margin: auto;
    }
    
    
    

    This creates a "jump" due to variable heights... to solve that, try something like this: Select the tallest image of a list

    Or use media-query to set your own fixed height.

提交回复
热议问题