How to make bootstrap carousel image responsive?

前端 未结 6 1192
感情败类
感情败类 2020-12-01 10:57

I want to keep the same ratio of the images. The problem is it streches when the browser is wide. and squezes when it\'s reduced.

I have checked all SO question here

6条回答
  •  遥遥无期
    2020-12-01 11:37

    I found it best to remove the following.

    .carousel-inner > .item > img {
        position: absolute;
        top: 0;
        left: 0;
        min-width: 100%;
        height: 500px;
    }
    

    and in .carousel remove:

    height: 500px;
    

    and in .carousel .item remove

     height: 500px;
    

    for me this made the image work the way I wanted it to but be sure to insert an image in your html first or else I think it will just collapse into nothingness if you are working locally.

    edit: Another user suggested I add this
    Please Note that if the image shows grey bars on either side or even on one side, I'd recommend keeping

    .carousel-inner > .item > img {
        min-width: 100%;
    }
    

提交回复
热议问题