Cascading Style Sheets (CSS) is a formatting language that separates the presentation or style of the web page from its content. With CSS a consistant 'style' can be applied across many pages.
Although this is an introductory tutorial I assume you are familiar with HTML and have developed web pages. If you are not familiar with the development of internet pages using HTML or you have never heard of CSS before you need to learn the basics of web page development else where. Basic web development
If we try to understand the fundamental rules of the CSS formating language there are very few concepts to learn.
Select a single HTML tag. Tag_name { style_property : value ; style-property : value ; etc... } This is any HTML element tag we want to style. Place each style attribute and its assigned value between curly braces. Separate the style attribute from its value with a colon and follow each line of style properties with a semi-colon. Paragraph tags <p> might be assigned lightblue backgrounds and black text like this: p { background-color: lightblue; color: black; )
Select multiple tags Tag1_name, Tag2_name, Tag3_name, etc.. { style goes between the curly braces } Here we want several tags to have the same style. Note the separating commas !
Select a tag with a particular class name Tag_name.Class_Name, etc.. { style goes between the curly braces } Here we have identified the tag when its class="cLass_Name". We assign the class attribute to the tag like this -- for example < p class='class-name' >
Select all tags with the same class name. .class_Name, etc.. { style goes between the curly braces } Here we have identified a class and any tag that has class="CLass_Name" will be selected. Note the period in front of the class_name.
Pseudo classes such as :hover may also be styled. :hover { style goes between the curly braces } In most browsers only anchor tags with the :link, :visited, :hover pseudo classes can be styled. These pseudo classes are not HTML markup tags they are implemented in the style language.
You can use the class_name and pseudo class together so that: a.class_name:hover { style goes between the curly braces } This can be very helpful in separately identifying anchor tags in menu elements from anchor tags in the HTML body.
Tag elements that have id='unique_name' can be styled using '#' #unique_name { style goes between the curly braces } If the element has a unique name I am not sure you would ever want to create a 'style' in the <style> section of the web page -- it probably makes more sense to place the style attributes directly into the tag element like this <p id='unique' style='color:red; font-size: 14px;' > .
Obviously different tag elements with identical #id_name can be styled the same. Different tag elements with the same #id_name can be styled differently.So tag_name1#unique_name { style goes between the curly braces } and...... tag_name2#unique_name { style goes between the curly braces } As I commented above, the #id is typically unique in web page design so that scripting languages can deal with a HTML element. Style is usually applied across web pages to many similar tags. The object selection described here is inconsistant with the general purpose of CSS but perhaps it may be useful in solving some future design problem.
The final HTML element selection rules enable complex tag selection based on the tags parent child relationship to other HTML elements. body div.divname p { style goes between the curly braces } This style would only be applied to <p> tags within the <div> element that has the class name 'divname' that is within the <body> tag. All other <p> tags would not be assigned this style. Notice that there are no commas. If we added a comma after p we could list another tag that could share the style if it too was the child of the div class and body.