1.

In how many ways can a CSS be written for an HTML file?

Answer»

Selectors are used to SELECTING the content which you want to add styles too. There are five TYPES of selectors in CSS.

1. Type Selector (Element Selector): selects all the elements which MATCH the given type.

Example: h1 [Selects all the elements with h1 tag.]

2. ID Selector: selects the element which matches the ID value. It’s suggested that there should be only one element for a given ID.

Example: #first-name [Selects the element having first-name as an ID value.]

3. Class Selector: selects all the elements which match the given class name.

Example: .blue [selects all the elements with a class name blue.]

4. Universal Selector: selects all the elements in the DOCUMENT.

Example: * [Selects all the elements in the document.]

5. Attribute Selector: selects the element which matches the attribute value.

Example: a [target = “_blank”] selects all the anchor elements with attribute value is _blank.

90% of the times we use class selectors to apply styles. Only for specific conditions, we use other selectors. It’s better to use class selectors to apply styles for similar elements like labels in a form.



Discussion

No Comment Found