Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't values on the ::after pseudo-element be unset?

Below is a very simple example to demonstrate the issue.

All paragraph elements are styled red, but then the content generated by ::after should not be red anymore. Its color should be unset.

Why doesn't this work?

<!DOCTYPE html>
<html>
<head>
<style>
p {color:red}
p::after { 
  content: " and after";
  color: unset;
}
</style>
</head>
<body>
<p>before</p>
</body>
</html>

With a property like color, at least a different value can be manually specified. But I've run into a case where I want to use filter: brightness(1.2) on an element but not allow that filter to affect the ::after content.

like image 478
Mentalist Avatar asked Jul 30 '19 06:07

Mentalist


1 Answers

According to this:

unset is a CSS value that's the same as "inherit" if a property is inherited or "initial" if a property is not inherited

As after element is inherited from p element, unset will be as inherit and the color will be the red same as p tag.

Use initial instead

<!DOCTYPE html>
<html>
<head>
<style>
p {color:red}
p::after { 
  content: " and after";
  color: initial;
}
</style>
</head>
<body>
<p>before</p>
</body>
</html>
like image 75
Kareem Dabbeet Avatar answered Oct 21 '22 14:10

Kareem Dabbeet