Explore 100's Of Free Video Tutorials

Keep Learning, Keep Coding & Keep Sharing

CSS

CSS class selector

Notes:

CSS class selector demo:

Class selector:
To select tags by their “class attribute value” and apply styles on them we use class selector.

Syntax of CSS rule-set / rule:
selector
{
declaration list;
}

To implement class selector, In place of selector, we write class attribute value preceded by period(dot).

Syntax of class selector:
tagname class=”classattributevalue”
.classattributevalue
{
declaration list;
}
It selects every html tag which has specified class attribute value and applies styles on them.

Example for class selector:
p class=”solidborder”
. solidborder
{
border: 2px solid red;
}
It selects every html tag available on the page with a specified class attribute value and applies specified styles on them.

You can specify same class attribute value to more than one tag, if required.
An html element can have list of class attribute values separated by white space, if required.

Interview Questions:

1. Which symbol indicates class selector in CSS?
a. hash
b. plus
c. dot
d. greater than
Answer: c

2. To select tags by their class attribute value which selector is used?
a. class selector
b. id selector
c. tag selector
d. sibling selector
Answer: a