Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display a box-shadow through a semi-transparent div?

Tags:

html

css

opacity

I have a div element with this css :

  height: 50px;
  width: 50px;
  background-color: rgba(0, 0, 0, 0.5);
  box-shadow: 20px 20px 5px red;

screenshot of the result

And despite the fact that it's semi transparent, I can't see the red shadow under the div. Is there any way to display it ?

edit : as it's probably a rendering issue, I tested in Google Chrome, Firefox and IE, same result.

like image 746
Romain Durand Avatar asked Sep 13 '25 01:09

Romain Durand


1 Answers

You can not get this with a box-shadow, as far as I know.

You can get it with a pseudo element:

.test {
    height: 50px;
    width: 50px;
    background-color: rgba(0, 0, 0, 0.5);
    position: relative;
}

.test:after {
    content: "";
    width: 100%;
    height: 100%;
    left: 20px;
    top: 20px;
    background-color: red;
    box-shadow: 0px 0px 5px red;
    position: absolute;
    z-index: -1;
}

I have set a shadow in the pseudo element only for the blurring. The other shadow properties go to the left and top properties of the pseudo element.

fiddle

like image 56
vals Avatar answered Sep 14 '25 15:09

vals