Giannis Grivas
Giannis Grivas

Reputation: 3412

How to ignore body element style when there is a class at element inside

Look, i have the html below:

<body style="color:red;">
text inside 1
<p>
text inside p
...
</p>
<div class="divable1">
text inside div 1
</div>

</body>

and i want only "text inside 1" and "text inside p" to have color red BUT "text inside div 1" i want to ignore the style of the body element.

How is this possible with CSS?

Thank you in advance!

Upvotes: 2

Views: 2083

Answers (3)

einord
einord

Reputation: 2325

I'm aware that this question was asked a very long time ago, but it could possibly be done by unsetting one or all properties:

body {
  color: red;
}

.divable1 {
  all: unset; /* resets everything */
  color: unset; /* resets specific property */
}

Upvotes: 0

o--oOoOoO--o
o--oOoOoO--o

Reputation: 770

This is basic CSS hierarchy, you can't ignore the rules, but you can easily overwrite them:

body {
    color: red;
}
.divable1 {
    color: green;
}

http://jsfiddle.net/vLtqjjpk/

Upvotes: 2

Quentin
Quentin

Reputation: 943571

There is no way to ignore rules in CSS, only to override them. Write a ruleset with:

  • A selector that matches the div (such as .divable1)
  • A rule that changes the color property so it has a value other than the default, which is inherit, such as color: black.

Upvotes: 4

Related Questions