Responsive circle and image fit on circle

前端 未结 4 363
深忆病人
深忆病人 2021-01-23 17:38

I want to create a responsive circle and I want to fit the image. I want to use img tag not with css (background)

Here is what i\'ve tried

.         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-23 17:58

    Here's a solution that has the image be responsive according to the width of its parent container.

    .container {
      /* Feel free to adjust the values here so you can see it being responsive */
      width: 200px;
    }
    
    .circle {
      position: relative;
      width: 100%;
      height: 0;
      padding: 100% 0 0;
      border-radius: 50%;
      overflow: hidden;
      border: 1px solid gray;
    }
    
    .circle img {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    You can try it out on CodePen

提交回复
热议问题