Stretch and fill image in Bootstrap carousel

前端 未结 14 1320
情歌与酒
情歌与酒 2021-01-11 13:11

I am using bootstrap carousal and having some problem with image height and width. Even though I define it in the img attribute it still displays a

14条回答
  •  一向
    一向 (楼主)
    2021-01-11 14:02

    img tag using "object-fit: cover" property

    .carousel {
        height: 300px;
    }
    
    .carousel-inner {
        height: 100%;
    }            
    
    .item {
        width: 100%;
        height: 100%;                
    }
    
    .item img {
        object-fit: cover;
    /*
        object-fit: fill;
        object-fit: none;
        object-fit: contain;
        object-fit: scale-down;
    */
    }
    
    
    
    
            
    

    Codepen

  • Editor
  • Full view
  • Version of background .item

提交回复
热议问题