RenegadeAndy
RenegadeAndy

Reputation: 5690

Can you assign a css entry an html selector and a class selector?

If I have the following piece of CSS:

p {
color:red;
}

This will apply to all P html elements. Is there a way I can also assign a class based selector to that same css object? So I could then also have <h1 class="redText"> which would also use the css object above - as well as it applying to all <p> elements?

Upvotes: 0

Views: 48

Answers (1)

Ian Hazzard
Ian Hazzard

Reputation: 7771

Use .redText,p to select everything with a class of "redText", and every "P" element. The . is the class selector, so .redText matches every thing with that class. Use a comma to separate multiple element matches.

.redText,
p {
  color: red;
}
<h1 class="redText">Red Text!!!!!</h1>

<p>Red text!</p>

<h1>Normal text!!!</h1>

Upvotes: 2

Related Questions