Farah Javed
Farah Javed

Reputation: 97

How do you use one class for multiple tags?

I want to use one class for two different tags. Do I have to declare it like <h1 class="line"> and then <p class="line"> ??? and in the CSS would it just be .line and it would change it for both then? Please help. Thanks

Upvotes: 0

Views: 532

Answers (2)

MC Emperor
MC Emperor

Reputation: 22977

You need to declare the class within your CSS:

.line {
    background-color: red;
}

And then you can apply the class to your HTML elements:

<tag1 class="line" />
<tag2 class="line" />

Upvotes: 2

i alarmed alien
i alarmed alien

Reputation: 9520

Easy: just use the same class for several different elements. E.g.:

HTML:

<div class="line">
    Lorem ipsum...
</div>

<p class="line">
    Blah blah blah
</p>

CSS: for example, give each element with the .line class a red border:

.line {
    border: 1px solid red;
}

See the jsfiddle!

Upvotes: 1

Related Questions