Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

CSS class selector

CSS Class Selector

Before proceeding to CSS class selector, I’ll advice you to read CSS tutorial for beginners, CSS Properties and Values and CSS Selectors first. If you have already read, then we’re good to proceed.


Introduction to css class selector

A class in CSS can be explained as a category in which different elements have same styling. Didn’t get it? Okay,

Suppose we have a

, a and an 

tag in our webpage. We want text color for all three of them to be red. So rather than targeting all three of them separately. We can specify a class for these three elements and then specify the styling for that class. That way we won’t have to write the same thing three times in CSS.

Usage:

this is div text

this is paragraph text

this is h4 text

this is any other paragraph text.

and our CSS 

.red-color{
   color:red;
}

we can see the result :

See the Pen Css Class by The SuperKat (@thesuperkat) on CodePen.


So as we see in the example above, we have three elements with class “red-color”. So we specified styling for .red-color class in the CSS and BINGO! , all the HTML Elements with class “red-color” attribute have red colored text now.

Guess What? : you can specify multiple classes for the same element. Yes! you can by separating two classes with space.

For example:

Hello

and

.red-color{
  color:red;
}

.yellow-background{
  background:yellow;
}

this will style Hello in red color and with yellow background. That’s pretty much about you need to know for starters about CSS Class selector. Because all at once is nothing at end. So take out your inner demon of creativity and do something mind blowing already.

Next Step : CSS element selector

Related Links :

  • CSS * selector
  • CSS id selector

The post Css Class Selector appeared first on The Superkat.



This post first appeared on The SuperKat, please read the originial post: here

Share the post

CSS class selector

×

Subscribe to The Superkat

Get updates delivered right to your inbox!

Thank you for your subscription

×