How to Use Selectors in CSS
Selectors in CSS
The selector is an HTML element or tag that you define for different styles, the property is the attribute you wish to change, and each property can take a value. The property and value are surrounded by curly braces and separated by a colon:
HTML
selectors
Used to define styles associated to HTML tags.
| <HTML> body{ </style>
|
In above example, p and body selectors are looks like <p> and <body>.
Class
selectors
Used to define styles that can be used without redefining plain HTML
tags.
| <HTML> </style>
|
ID
selectors
Used to define styles relating to objects with a unique ID (ID selector
most often used in layers)
The property is the attribute you wish to change, and each property holds a
value. The property and value are separated by a colon and surrounded by curly
braces for example we define a selector body with background-color property
and background-color property has a color any value:
| body {background-color:red} |
If you wish to specify more than one property, you must separate each property with semi-colon. For example we wish to define a left aligned paragraph with blue color, the example is shown below:
| P
{text-align:center;color:red} |
To make the style definitions more readable, you can describe one property on each line, like this:
| P |
Grouping
You can group selectors. Separate each selector with a comma.
In the example below we have grouped all the header elements. All header elements
will be green:
| h1,h2,h3,h4,h5,h6
|
