3

I'm going straight to the point here. I want to create a simple window within an image. outside the window will have a opacity like on the sample picture.

I'm not really good when it comes to css so please bear with me.

.section2{
 }

.section2 .row{
 margin: 0;
}
.the-container{
 position: relative;
 width: 100%;
 height: 450px;
}
.the-container .text-center{
 background: #fff;
 opacity: .9;
}

.img-canvas{
position: absolute;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
width: 100%;
height: 100%;
background-image: url(https://www.aman.com/sites/default/files/styles/1371x706/public/amanpulo-location-1200-x-825.jpg?itok=4BQy9j-X);
background-size: 100% 100%;
background-position: 50% 50%;
background-attachment: scroll;
z-index: -1;
}
.window{
position:absolute;
width:50%;
height:50%;
background-size: cover;
top:0;
left:25%;
z-index: -1;
opacity: 1;
}
<section class="section2" style="height:100vh;">
<div class="row">
    <div class="col-md-10 col-md-offset-1">
        <div class="the-container">
            <div class="img-canvas"></div>
            <div class="window"></div>
        </div>
    </div>
</div>
</section>
something like this: enter image description here

and here's a fiddle for you to manipulate the code: https://jsfiddle.net/Lk21vL01/

thanks in advance.

ADH - THE TECHIE GUY
  • 4,125
  • 3
  • 31
  • 54
Sam Teng Wong
  • 2,379
  • 5
  • 34
  • 56
  • Hei!! Is it violating this stackoverflow regulation?! You should do it on your own. Not to asking question to get the whole things done by others. – Sherly Febrianti Nov 25 '16 at 04:07
  • @sherlyfebrianti, OP has posted their attempts, i wouldnt consider this asking people to do the whole thing per se – haxxxton Nov 25 '16 at 04:08
  • @sherlyfebrianti sorry for this. I've tried something but didn't put everything.. I have a header there but that takes the opacity.. however I can't really figure out how to make the both sides of the image. – Sam Teng Wong Nov 25 '16 at 04:08
  • hey this link could be helpful to you http://stackoverflow.com/questions/26622143/is-it-possible-to-make-certain-parts-of-an-image-transparent-in-html5-css – Geeky Nov 25 '16 at 04:09
  • @Geeky ty for this.. – Sam Teng Wong Nov 25 '16 at 04:11
  • @SamTengWong okay, i'm sorry too, maybe just some missunderstanding about your post. – Sherly Febrianti Nov 25 '16 at 04:16

2 Answers2

2

You were very close, you just needed to apply similar styling to your .window element and use background-attachment:fixed

see this updated jsfiddle

.section2{
}

.section2 .row{
  margin: 0;
}
.the-container{
  position: relative;
  width: 100%;
  height: 450px;
}
.the-container .text-center{
    background: #fff;
    opacity: .9;
}
.window,
.img-canvas{
    position: absolute;
    top: 0px;
    left: 0px;
    right: 0px;
    bottom: 0px;
    width: 100%;
    height: 100%;
    background-image: url(https://www.aman.com/sites/default/files/styles/1371x706/public/amanpulo-location-1200-x-825.jpg?itok=4BQy9j-X);
    background-size: 100% 100%;
    background-position: 50% 50%;
    background-attachment:fixed;
    z-index: -1;
    opacity: 0.5;
}
.window{
  position:absolute;
  width:50%;
  height:50%;
  top:0;
  left:25%;
  z-index: -1;
  opacity: 1;
}
haxxxton
  • 6,422
  • 3
  • 27
  • 57
2

Not the most proper way to achieve this, but you could use a box-shadow "hack" to create the effect you're looking for. Just set a box shadow around the window with 0 blur and a spread that will always bigger than the background (something like 1000, or even 5000 pixels).

#background {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  background: linear-gradient(to bottom, slategray, #333);
  overflow: hidden;
}

#window {
  position: absolute;
  width: 250px;
  height: 100px;
  top: 25%;
  left: 25%;
  box-shadow: 0 0 0 1000px rgba(255, 255, 255, 0.75);
}
<div id="background">
  <div id="window">
  </div>
</div>
Alfred Xing
  • 4,406
  • 2
  • 23
  • 34