3

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

enter image description here

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.

Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
user3710700
  • 301
  • 1
  • 4
  • 11
  • Could you paste some more code? HTML-structure as well as parent div's CSS would help. – pimmey Oct 16 '14 at 10:01
  • where is your section? I couldn't find any Xclass class in the html. – Bonomi Oct 16 '14 at 10:01
  • Try giving `.Xclass` a background that matches the main background. Otherwise you could always look into CSS Masking: http://www.hongkiat.com/blog/css-masking/ – Rvervuurt Oct 16 '14 at 10:03
  • `background: transparent` can't influence the parent container's background. You could create a background-image with a transparent circle in it. – pimmey Oct 16 '14 at 10:04

2 Answers2

5

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>
Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
  • Not that it matters but you could use a pseudo-element instead of the '#circle' div for slightly less HTML. +1 – Paulie_D Oct 16 '14 at 11:09
  • That is amazing! Can you explain why that works? Why does `overflow: hidden` cause any `box-shadow` properties to be clipped? – Luke Knepper Oct 05 '17 at 20:48
  • 1
    @LukeKnepper exactly. The box shadow of the inner circle will be clipped by the overflow:hidden parent. – Roko C. Buljan Oct 05 '17 at 20:51
0

Try

.Xclass {
  opacity: 0.7;
}

or

.Xclass {
 background-color: rgba(15,15,15,0.7);
}
aemonge
  • 2,289
  • 1
  • 24
  • 26