Pero B Pero B - 24 days ago 7
CSS Question

CSS background cut

this is my code, and as you can see body has some background image, and #cont should be white. But I want my div elements to be transparent in a way that I can see body background image. Any CSS tricks that can do that?



body {
margin: 0;
border: 0;
padding: 0;
height: 100%;
width: 100%;
background-image: url(image.png);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
#cont {
margin: 0;
border: 0;
padding: 0;
background-color: white;
}
#cont div {
margin: 20px;
border: 1px solid gray;
padding: 0;
width: 50px;
height: 50px;
float: left;
}

<div id="cont">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>




Answer

here is the snippet updated:

body {
  margin: 0;
  border: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background-image: url(https://placekitten.com/1000/1000);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover; /*include this*/
  background-attachment: fixed; /*include this*/
}
#cont {
  margin: 0;
  border: 0;
  padding: 0;
  background-color: white;
}
#cont div {
  margin: 20px;
  border: 1px solid gray;
  padding: 0;
  width: 50px;
  height: 50px;
  /*float: left; replaced by display inline-block*/
  display: inline-block; /*include this*/
  background: url(https://placekitten.com/1000/1000) center center no-repeat; /* <<< same body image*/
  background-size: cover; /*include this*/
  background-attachment: fixed; /*include this*/
}

Here is the full example: jsbin