Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have Pseudo Element Inherit Parents Background Color

Tags:

html

css

I have several pseudo elements that are related to varying different parent divs. All these divs have different background colors and I would like to before and after pseudo elements to inherit the background color of the parent div. I also want to do this without using JS and only CSS. I tried setting the background of the before and after elements to inherit, but they just show up transparent.

like image 612
Mav2287 Avatar asked Dec 19 '22 15:12

Mav2287


1 Answers

You can use background: inherit on the pseudo-elements:

#mydiv:after {
  background: inherit;
}

jsFiddle Demo

like image 86
BenM Avatar answered Jan 13 '23 23:01

BenM