CSS Syntax

Syntax in CSS

CSS Syntax : A CSS comprises of style rules that are interpreted by the browser and then applied to the corresponding elements in your document. A style rule is made of three parts

SelectorA selector is an HTML tag at which a style will be applied. This could be any tag like <h1> or <table> etc.  
PropertyA property is a type of attribute of HTML tag. Put simply, all the HTML attributes are converted into CSS properties. They could be color, border etc.  
ValueValues are assigned to properties. For example, color property can have value either red or #F1F1F1 etc.  

Declaration Block:

The declaration block can contain one or more declarations separated by a semicolon.

Example:                                                                                          

You can define a table border as follows
table{ border :1px solid #C00; }
The Attribute Selectors:
                        You can also apply styles to HTML elements with particular attributes.
input[type = “text”] {
   color: #000000;
}

There are following rules applied to attribute selector.

        p [lang] : Selects all paragraph elements with a lang attribute.

        p [lang=”fr”] : Selects all paragraph elements whose lang attribute has a value of exactly “fr”.

        p[lang~=”fr”] : Selects all paragraph elements whose lang attribute contains the word “fr”.

        p[lang|=”en”] : Selects all paragraph elements whose lang attribute contains values that are exactly “en”, or begin with “en-“.


Recommended Posts:

Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *