Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cover div or image with transparent color

Tags:

css

I have a div, and an image inside it. on the image I have the DB results, designed and placed with relative location on each div.
I want to cover some of the results (the most interesting one with color overlay), see image bellow: enter image description here

How should I do it without adding another div on top of it?
backgroup will not help here, because the image is higher z index than the div..

I want to be able to do it as easiest as I can with CSS, because I will get the property from the DB query , and set the class for the relevant result rows..

Does someone has creative idea please? :)

Thanks.

like image 557
gabi Avatar asked Oct 02 '14 18:10

gabi


People also ask

How do you make a div background transparent?

If you just want your element to be transparent, it's really as easy as : background-color: transparent; But if you want it to be in colors, you can use: background-color: rgba(255, 0, 0, 0.4);

How do I make a div background semi transparent?

To achieve this, use a color value which has an alpha channel—such as rgba. As with opacity , a value of 1 for the alpha channel value makes the color fully opaque. Therefore background-color: rgba(0,0,0,. 5); will set the background color to 50% opacity.

Is there a transparent color in CSS?

The CSS color name transparent creates a completely transparent color. Using rgba or hsla color functions, that allow you to add the alpha channel (opacity) to the rgb and hsl functions. Their alpha values range from 0 - 1.

How do I make background color transparent?

To set the opacity of a background, image, text, or other element, you can use the CSS opacity property. Values for this property range from 0 to 1. If you set the property to 0, the styled element will be completely transparent (ie. invisible).


2 Answers

div {
    position: relative;
}
div:before {
    content: "";
    display: block;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(255, 0, 0, .5);
}

You can also change the top, right, bottom and left values to offset the overlay from the image borders.

like image 62
Antoine Combes Avatar answered Sep 27 '22 21:09

Antoine Combes


well, with all the restrictions you have, the only thing I can think is this:

div{background:#f00}
img{opacity:.5}

not very elegant, but will work

like image 29
Devin Avatar answered Sep 27 '22 20:09

Devin