How to make an inverse transparent circle in CSS [

2019-02-18 16:43发布

问题:

This question already has an answer here:

  • Transparent hollow or cut out circle 5 answers

how do i make a section on color background transparent with css? here is example for this background

i still didn't try anything becouse i have no idea how to do that so please help me. if im putting its as div on div and typing in the css:

.Xclass{ background: transparent; }

its still show me the white background.

please help me guys.

回答1:

jsBin demo

  • Place an overflow:hidden square with no background.
  • Inside that square - put a circle with a high box-shadow spread radius

#image{
  position:relative;
  margin:0 auto;
  background: url(http://i.imgur.com/gVcxX9C.png);
  height:500px;
  width:600px;
}
#box{
  position:absolute;
  left:300px;
  top:200px;
  width:200px;
  height:250px;
  overflow:hidden; /* to contain #circle's box-shadow */
}
#circle{
  position:relative;
  margin:30px auto;
  width: 150px;
  height:150px;
  box-shadow: 0 0 0 100px #fff; /* !!! */
  border-radius:50%;
}
  <div id="image">
    <div id="box"><div id="circle"></div></div>
  </div>



回答2:

Try

.Xclass {
  opacity: 0.7;
}

or

.Xclass {
 background-color: rgba(15,15,15,0.7);
}