Responsive vertical center with overflow hidden

后端 未结 5 1112
北荒
北荒 2021-02-01 07:27

After searching both Stack Overflow and Google I still wonder how to vertical center a image that is bigger than it\'s parent element. I use no height, just max-height, because

5条回答
  •  有刺的猬
    2021-02-01 08:19

    If you dont need to use img tags (fiddle):

    CSS

    .imageContainer {
        margin: 0; 
        height: 200px; /* change it to your value*/
        width: 200px; /* or use fixed width*/
        background: transparent url('') no-repeat center;
        overflow: hidden; 
    }
    

    HTML

提交回复
热议问题