XtGem Forum catalog
ADS By Strikecoded:
Smash Your 2018/19 Jamb, Waec, Neco With CAMPUSBASE Visit Now.. Best Java, Android Games, Apps


No1. Naija Awarded Download Portal For Both Mobile And Pc Users..

Home | Blog | Search | Uploads

»Css Tutorials
You are viewing Tutorial 2 Of 18 Tutorials For Css Basics/Functions. View All Tutorials

»All Tutorials Collection


Tutorial 1: Introduction to CSS

Tutorial 2: CSS Syntax

Tutorial 3: CSS Classes

Tutorial 4: CSS IDs

Tutorial 5:CSS Divisions

Tutorial 6: CSS Spans

Tutorial 7: CSS Margins

Tutorial 8: CSS Padding

Tutorial 9: CSS Text Properties

Tutorial 10: CSS Font Properties

Tutorial 11: CSS Anchors, Links and Pseudo Classes

Tutorial 12: CSS Backgrounds

Tutorial 13: CSS Borders

Tutorial 14: CSS Ordered & Unordered Lists

Tutorial 15: CSS Width and Height Properties

Tutorial 16: CSS Classification

Tutorial 17: CSS Positioning

Tutorial 18: CSS Pseudo Elements

Tutorial 2: CSS Syntax

The syntax for CSS is different than that of (X)HTML markup. Though it is not too confusing, once you take a look at it. It consists of only 3 parts.

selector { property: value }

The selector is the (X)HTML element that you want to style. The property is the actual property title, and the value is the style you apply to that property.
Each selector can have multiple properties, and each property within that selector can have independent values. The property and value are seperated with a colon and contained within curly brackets. Multiple properties are seperated by a semi colon. Multiple values within a property are sperated by commas, and if an individual value contains more than one word you surround it with quotation marks. As shown below.

body {
background: #eeeeee;
font-family: "Trebuchet MS", Verdana, Arial, serif;
}


As you can see in the above code I have seperated the color from the font-family with a semi-colon, seperated the various fonts with commas and contained the "Trebuchet MS" within quotations marks. The final result sets the body color to light grey, and sets the font to ones that most users will have installed on there computer.
I have changed the way I layout my code, but you can arrange it in one line if you choose. I find that it is more readable if I spread each property to a seperate line, with a 2 space indention.



Inheritance
When you nest one element inside another, the nested element will inherit the properties assigned to the containing element. Unless you modify the inner elements values independently.
For example, a font declared in the body will be inherited by all text in the file no matter the containing element, unless you declare another font for a specific nested element.

body {font-family: Verdana, serif;}

Now all text within the (X)HTML file will be set to Verdana.
If you wanted to style certain text with another font, like an h1 or a paragraph then you could do the following.

h1 {font-family: Georgia, sans-serif;}
p {font-family: Tahoma, serif;}


Now all <h1> tags within the file will be set to Georgia and all <p> tags are set to Tahoma, leaving text within other elements unchanged from the body declaration of Verdana.
There are instances where nested elements do not inherit the containing elements properties.
For example, if the body margin is set to 20 pixels, the other elements within the file will not inherit the body margin by default.

body {margin: 20px;}



Combining Selectors
You can combine elements within one selector in the following fashion.

h1, h2, h3, h4, h5, h6 {
color: #009900;
font-family: Georgia, sans-serif;
}


As you can see in the above code, I have grouped all the header elements into one selector. Each one is seperated by a comma. The final result of the above code sets all headers to green and to the specified font. If the user does not have the first font I declared it will go to another sans-serif font the user has installed on there computer.



Comment tags
Comments can be used to explain why you added certain selectors within your css file. So as to help others who may see your file, or to help you remember what you we're thinking at a later date. You can add comments that will be ignored by browsers in the following manner.

/* This is a comment */

You will note that it begins with a / (forward slash) and than an * (asterisks) then the comment, then the closing tag which is just backward from the opening tag * (asterisks) then the / (forward slash).
« Previous
Jump to Tutorial:
Next »


Page Statistics

DataLoads
Online1
Today's Hits 1
Total Today's Hits1
Total Hits This Week 71
Total Page Hits 9796
Total Forum Members190

Close Page Information

Go BackPromote Forum Services Members About us Terms of use Advertise News update Contact us Feedback

chart1FOLLOW US ON

FBTWG LDRS
Back to the Top

Copyright © . Theme by STRIKECODED TECH.

Desktop View