Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent foreground

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?

like image 804
Randomblue Avatar asked Oct 04 '11 00:10

Randomblue


People also ask

What is background vs foreground?

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.

What is an image with a transparent background called?

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.

How do I get a transparent background image?

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.

How do I make a layer slightly transparent?

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.


1 Answers

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" />');
like image 63
alex Avatar answered Sep 28 '22 12:09

alex