You can use css3 properties along with pseudo-elements to create this effect:
The trick is to draw a field with the :before
or :after
pseudo-element. We can apply the background
property to the inner translucent background. Although for the external background
we can use the large value of box-shadow
.
HTML:
<div class="box"></div>
CSS
.box { position: relative; overflow: hidden; height: 120px; width: 250px; } .box:before { background: rgba(0, 0, 0, 0.3); box-shadow: 0 0 0 1000px #000; position: absolute; height: 50px; width: 50px; content: ''; left: 0; top: 0; }
html, body { height: 100%; } body { background: linear-gradient(to top, #ff5a00 0, #ffae00 100%); margin: 0; } .box { position: relative; margin: 30px 20px; overflow: hidden; height: 120px; width: 250px; } .box:before { background: rgba(0, 0, 0, 0.3); box-shadow: 0 0 0 1000px #000; position: absolute; height: 50px; width: 50px; content: ''; left: 0; top: 0; }
<div class="box"></div>
source share