mikko
mikko

Reputation: 851

Select element but not certain inner elements in CSS

If I have this HTML

<p class="all">Example <span class="but">text</span> here.</p>

is it possible to write a simple CSS style to color the words Example and here. to red but leave the text to default color?

Upvotes: 1

Views: 48

Answers (2)

Anubhav pun
Anubhav pun

Reputation: 1323

not:- set a color for the span class but only

<style>
    .all{ color:red;}
    :not(but)({color:initial;}
    </style>

<p class="all">Example <span class="but">text</span> here.</p>

Upvotes: 0

Ajay Malhotra
Ajay Malhotra

Reputation: 838

You can use color:initial property in css.

check the given below code snippet.

p{color:red}
.but{color:initial;}
<div>
  <p class="all">Example <span class="but">text</span> here.</p>
  </div>

Upvotes: 2

Related Questions