2

this is my code:

body{
   background: url(https://static.pexels.com/photos/29628/pexels-photo.jpg) no-repeat center center fixed; 
 -webkit-background-size: cover;
 -moz-background-size: cover;
 -o-background-size: cover;
 background-size: cover; 
}

.header{
   height:2em;
   width:100%;
   position:fixed;
   top:0; left:0;
   background-color:white;
}
.main{
   width:100%;height:10em;
   margin-top:5em;
   background-color:white;
}
.mainPanel{  
   width:50%;
   margin:auto;
   background-color:yellow;
   height:5em;
}
<html>
  
  <body>
    <div class="header">
    </div>
    <div class="main">
      <div class="mainPanel">
        
      </div>
    </div>
  </body>
  
</html>

I want that the yellow div is transparent and shows the background image of body. That the yellow div go trough the white div behind it and shows the background image of body. Is that possible? I hope it comes clear what i meant.

F. Dengler
  • 63
  • 5

2 Answers2

0

The only workaround I can think of would involve breaking your white box into three rectangles and arranging them to form a window of sorts. Here, try this out:

body {
   background: url(https://static.pexels.com/photos/29628/pexels-photo.jpg) no-repeat center center fixed; 
   background-size: cover; 
}

.header {height:2em;width:100%;position:fixed;top:0; left:0;}

.main {
    width: 100%;
    height: 10em;
    margin-top: 5em;
}
.mainPanel{  
    width:50%; 
    margin:auto;
    height:5em;
}
<html>
   <body>

   <div id="left-rectangle" style="background-color: white; width: 25%;height: 160px; position: absolute;"></div>
   <div class="right-rectangle" style="background-color: white; width: 25%; float: right; height: 160px;"></div>
   <div class="center-rectangle" style="position: absolute;margin-left: 25%;background-color: white;width: 50%;height: 80px;margin-top: 80px;"></div>
   <div class="header">
   </div>
   <div class="main">
   </div>

   </body>

</html>
Aziz
  • 7,685
  • 3
  • 31
  • 54
the_lost_one
  • 127
  • 10
0

You could simply repeat the background, and since it has a fixed position, it will be exactly like the body background and you will not notice a difference.

body, .mainPanel {
  background: url(https://static.pexels.com/photos/29628/pexels-photo.jpg) no-repeat center center fixed;
  background-size: cover;
}

Simply extend the background of body to .mainPanel to create the illusion.

Demo: jsFiddle

html, body {padding: 0; margin: 0;}

body, .mainPanel {
  background: url(https://static.pexels.com/photos/29628/pexels-photo.jpg) no-repeat center center fixed;
  background-size: cover;
}

.header {
  height: 2em;
  width: 100%;
  position: fixed;
  top: 0; left: 0;
  background-color: #EEE;
}

.main {
  width: 100%;
  height: 10em;
  margin-top: 5em;
  background-color: white;
}

.mainPanel {
  width: 50%;
  margin: auto;
  height: 5em;
  border:1px dashed #CCC; /* just for demo */
}
<div class="header">header</div>
<div class="main">
  <div class="mainPanel">
  </div>
</div>
Aziz
  • 7,685
  • 3
  • 31
  • 54