Sei sulla pagina 1di 5

CSS Basics

Defining Classes For Any Tag


Using a class selector gives you the ability to set up an independent style that you can then apply to any HTML tag. Unlike an HTML selector, which automatically targets a specific tag, a class is given a unique name that is then specified using the style attribute in the HTML tag or tags you want to use it in.
Class Selector Property Value

.instructor { font-size : 1em }

Declaration

The general syntax of a CSS rule using a class selector

The general syntax of a dependent class selector rule

Defining ID Selectors to Identify an Object


Like the class selector, the ID selector can be used to create unique styles that are independent of any particular HTML tag. Thus they can be assigned to any HTML tag. IDs are used in HTML layout to help establish the structure of your page, identifying unique elements in the code. IDs are also cornerstone of dynamic HTML (DHTML) in that they allow JavaScript functions to identify a unique object on the screen. This means that unlike a class, an ID can be used only once on a page to define element as an object. This object then can be manipulated using JavaScript.

The general syntax for an ID selector

The general syntax for the dependent ID selector rule.

Defining Selectors To Have The Same Styles


If you want two or more selectors to have the same declarations, just put the selectors in a list separated by commas. The general syntax for a selector grouping is shown below.

Potrebbero piacerti anche