Bootstrap carousel with fixed height: center image horizontally or vertically based on image dimensions

前端 未结 4 1892
借酒劲吻你
借酒劲吻你 2021-02-07 15:05

I have a bootstrap carousel with a fixed height. Here is the CSS:

.carousel-custom .carousel-outer {
  position: relative;
}


@media(min-width: 992px){
    .car         


        
4条回答
  •  不知归路
    2021-02-07 15:49

    simply use image on absolute if your slider height is fixed

    
    

    css

    .carousel {
      width: 500px;  /*test width*/
      height: 300px; /*what ever height */
    }
    
    .middle {
      position: relative;
      height: 300px; /*what ever height */
    }
    
    .middle img {
      max-width: 100%;
      max-height: 100%; /*what ever height */
      margin: auto;
      position: absolute;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
    }
    

    see fiddle

提交回复
热议问题