CSS Cut out circle from a rectangular shape

前端 未结 3 1323
眼角桃花
眼角桃花 2020-11-27 21:15

I managed to achieve this effect: http://jsfiddle.net/6z3msdwf/1/ but I am not really happy with the markup. Also, there is an weird bug in IE 10/11 where a 1px gap is shown

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 21:52

    You could use a circular gradient

    div {
      height: 150px;
      margin: 5em 2em;
      background: radial-gradient(circle at top center, transparent, transparent 70px, black 70px, black);
      border-radius: 8px;
      position: relative;
    }
    .circle {
      width: 120px;
      height: 120px;
      background: red;
      border-radius: 50%;
      position: absolute;
      top: 0;
      left: 50%;
      transform: translate(-50%, -50%);
    }
    body {
      background-image: url(http://www.fillmurray.com/1000/1000);
      background-size: cover;
    }

提交回复
热议问题