I would like to add a semi-transparent uniform layer as a foreground for a div
element. What is the best way to do that?
What are the foreground, middle ground, and background? The element of the photo closest to you makes up the foreground. The furthest element away from you is the background, while the middle ground makes up the area in between.
A PNG is an image file type that allows you to have no background color. Most images cover a certain number of pixels and have color in all of those pixels, even if that color is white. A transparent background has nothing in the background pixels, allowing what's behind it to show through.
Go to Select > Invert. On the right side of the screen, right-click on your image and select Add Alpha Channel. This will provide a transparent background.
Select the desired layer, then click the Opacity drop-down arrow at the top of the Layers panel. Click and drag the slider to adjust the opacity. You'll see the layer opacity change in the document window as you move the slider. If you set the opacity to 0%, the layer will become completely transparent, or invisible.
You could use this CSS...
div.parent {
position: relative;
}
/* this div is a descendent of the div above */
div.child {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
opacity: .6;
background: #fff;
}
jsFiddle.
If you want mouse events to go through this cover, add pointer-events: none
to the div.child
.
You tagged it jQuery, so to add this child element via jQuery...
$('div.parent').append('<div class="child" />');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With