Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I cover a div with a semi-transparent image?

Tags:

html

jquery

css

I want to cover a <div> so it looks like it has a semi-transparent block over it.

I am using jQuery but I do not know how to do it.

Any help thanks...

like image 739
gringoLoco007 Avatar asked Nov 26 '25 07:11

gringoLoco007


1 Answers

If you have another div, you can just get the dimensions + position like

var $somediv = $('#some_div_element'),
    pos      = $.extend({
       width:    $somediv.outerWidth(),
       height:   $somediv.outerHeight()
    }, $somediv.position());

and then use it while dynamically creating an overlay

$('<div>', {
    id:    'overlay',
    css:   {
        position:         'absolute',
        top:              pos.top,
        left:             pos.left,
        width:            pos.width,
        height:           pos.height,
        backgroundColor:  '#000',
        opacity:          0.50
    }
}).appendTo($somediv);

Example: http://www.jsfiddle.net/GkFu4/1/

like image 111
jAndy Avatar answered Nov 27 '25 20:11

jAndy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!