Css Syntax
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:
1 > Selector: A selector is an HTML tag at which a style will be applied. This could be any tag like <h1> or <table> etc.
2 > Property: A 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.
3 > Value: Values are assigned to properties. For example, color property can have the value either black or #000000 etc.
You can put CSS Style Rule Syntax as follows :
selector { property: value }
Ex:
h1 {
color: #778899; //light blue color .
}
Types of Selectors :
(1) Universal Selectors - The universal selector are the quite simply matches the name of any element type, Rather than selecting elements of a specific type
Ex:
* {
color: #000000;
}
This rule renders the content of every element in our document in black.
.black {
color: #000000;
}
This rule renders the content in black for every element with class attribute set to black in our document. You can make it a bit more particular.
(3) ID Selectors - You can define style rules based on the id attribute of the elements. All the elements having that id will be formatted according to the defined rule.
Ex:
#black {
color: #000000;
}
This rule renders the content in black for every element with id attribute set to black in our document. You can make it a bit more particular.
(4) Child Selectors - You have seen the descendant selectors. There is one more type of selector, which is very similar to descendants but have different functionality.
}
This rule will render all the paragraphs in black if they are a direct child of the <body> element. Other paragraphs put inside other elements like <div> or <td> would not have any effect of this rule.
(5) Attribute Selectors - You can also apply styles to HTML elements with particular attributes. The style rule below will match all the input elements having a type attribute with a value of text:
Ex:
input[type="text"]{
color: #000000;
}
The advantage to this method is that the <input type="submit" /> element is unaffected, and the color applied only to the desired text fields.
Grouping Selectors - You can apply a style to many selectors if you like. Just separate the selectors with a comma, as given in the following example:
h1, h2, h3 {
color: #36C;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;
}
This define style rule will be applicable to h1, h2 and h3 element as well. The order of the list is irrelevant. All the elements in the selector will have the corresponding declarations applied to them.
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:
1 > Selector: A selector is an HTML tag at which a style will be applied. This could be any tag like <h1> or <table> etc.
2 > Property: A 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.
3 > Value: Values are assigned to properties. For example, color property can have the value either black or #000000 etc.
You can put CSS Style Rule Syntax as follows :
selector { property: value }
Ex:
h1 {
color: #778899; //light blue color .
}
Types of Selectors :
(1) Universal Selectors - The universal selector are the quite simply matches the name of any element type, Rather than selecting elements of a specific type
Ex:
* {
color: #000000;
}
This rule renders the content of every element in our document in black.
(2) Class Selectors - You can define style rules based on the class attribute of the elements. All the elements having that class will be formatted according to the defined rule.
Ex:.black {
color: #000000;
}
This rule renders the content in black for every element with class attribute set to black in our document. You can make it a bit more particular.
(3) ID Selectors - You can define style rules based on the id attribute of the elements. All the elements having that id will be formatted according to the defined rule.
Ex:
#black {
color: #000000;
}
This rule renders the content in black for every element with id attribute set to black in our document. You can make it a bit more particular.
(4) Child Selectors - You have seen the descendant selectors. There is one more type of selector, which is very similar to descendants but have different functionality.
Ex:
body > p {
color: #000000;}
This rule will render all the paragraphs in black if they are a direct child of the <body> element. Other paragraphs put inside other elements like <div> or <td> would not have any effect of this rule.
(5) Attribute Selectors - You can also apply styles to HTML elements with particular attributes. The style rule below will match all the input elements having a type attribute with a value of text:
Ex:
input[type="text"]{
color: #000000;
}
The advantage to this method is that the <input type="submit" /> element is unaffected, and the color applied only to the desired text fields.
Grouping Selectors - You can apply a style to many selectors if you like. Just separate the selectors with a comma, as given in the following example:
h1, h2, h3 {
color: #36C;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;
}
This define style rule will be applicable to h1, h2 and h3 element as well. The order of the list is irrelevant. All the elements in the selector will have the corresponding declarations applied to them.
0 comments:
Post a Comment