by eturo
In this tutorial you will learn how to make your first style sheet. You will get to know about the basic CSS model and which codes are necessary to use CSS in an HTML document.
In this tutorial you will learn how to make your first style sheet. You will get to know about the basic CSS model and which codes are necessary to use CSS in an HTML document.
Many of the properties used in CSS are similar to those of HTML. Thus, if you are used to use HTML for layout, you will most likely recognize many of the codes. Let us look at a concrete example.
The basic CSS syntax
Let's say we want a nice red color as the background of a webpage:
Using HTML we could have done it like this:
body bgcolor="#FF0000"
With CSS the same result can be achieved like this:
body {background-color: #FF0000;}
As you will note, the codes are more or less identical for HTML and CSS.
The above example also shows you the fundamental CSS model:
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 semicolon. Multiple values within a property are seperated 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;
}
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 tags within the file will be set to Georgia and all tags are set to Tahoma, leaving text within other elements unchanged from the body declaration of Verdana.