CSS Circular Cropping of Rectangle Image

前端 未结 9 1359
北荒
北荒 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:12

    Johnny's solution is good. I found that adding min-width:100%, really helps images fill the entire circle. You could do this with a combination of JavaScript to get optimal results or use ImageMagick - http://www.imagemagick.org/script/index.php if you're really serious about getting it right.

    .image-cropper {
    
      width: 35px;
    
      height: 35px;
    
      position: relative;
    
      overflow: hidden;
    
      border-radius: 50%;
    
    }
    
    .image-cropper__image {
    
      display: inline;
    
      margin: 0 auto;
    
      height: 100%;
    
      min-width: 100%;
    
    }

提交回复
热议问题