CSS Circular Cropping of Rectangle Image

前端 未结 9 1364
北荒
北荒 2020-12-12 15:32

I want to make a centered circular image from rectangle photo. The photo\'s dimensions is unknown. Usually it\'s a rectangle form. I\'ve tried a lot of methods:

CSS:

9条回答
  •  轮回少年
    2020-12-12 16:14

    I know many of the solutions mentioned above works, you can as well try flex.

    But my image was rectangular and not fitting properly. so this is what i did.

    .parentDivClass {
        position: relative;
        height: 100px;
        width: 100px;
        overflow: hidden;
        border-radius: 50%;
        margin: 20px;
        display: flex;
        justify-content: center;
    }
    

    and for the image inside, you can use,

    child Img {
        display: block;
        margin: 0 auto;
        height: 100%;
        width: auto;
    }
    

    This is helpful when you are using bootstrap 4 classes.

提交回复
热议问题