The Brave Programmer - Blogging and coding
Not for the faint hearted
<H1>Blog Posts From The Brave Programmer</H1>
 

Blog Posts From The Brave Programmer

Minimize
Mar2

Written by:Robert Bravery
2009/03/02 08:17 AM 

Cascading Style Sheets (CSS) is a simple mechanism for adding style. It is a stylesheet language used to describe the presentation (that is, the look and formatting) of a document written in a markup language. Today we are looking at the basics of CSS.

Cascading Style Sheets (CSS) is a simple mechanism for adding style. It is a stylesheet language used to describe the presentation (that is, the look and formatting) of a document written in a markup language. Today we are looking at the basics of CSS.

CSS is designed primarily to enable the separation of document content (written in HTML or a similar mark-up language) from document presentation, including elements such as the colours, fonts, and layout.

There are various ways of linking these style rules to your HTML documents, but the simplest method for starting out is to use HTML's STYLE element. This element is placed in the document HEAD, or by using the Style property of an individual tag, e.g. h1. The style element contains the style rules for the page. But the most common way of using a Style element is by putting it into a external Style sheet. A file with css extension. This is then linked to the HTML page.

Generally each style is made up of a selector, property and value. This is know as a style rule. The selector is normally a html element, eg Body, H1 etc. A property is some property of that element, eg font, color, size. The value specifies the value of that property, e.g., red, 12px.

By using the HTML style element you can define these styles in-line, or within the HTML file. In the header it might look like this.

Note: I had to put spaces in the opening tags for formating issues.
view source
print?

< HEAD>
< TITLE>CSS Example< /TITLE>
< STYLE TYPE="text/css">
H1 { font-size: x-large; color: red }
H2 { font-size: large; color: blue }
< /STYLE>
< /HEAD>

Putting the style in an external style sheet follows the exact same syntax as above, but without the HTML elements.
view source
print?

H1 { font-size:x-large; color: red } 

But the style could also be in-line to the tag. For example we might want to change the look of the H1 style. h1 style="font-size: x-large; color: red"

An external style sheet may be linked to an HTML document through HTML's <strong class=" html="">LINK element. External style sheets do not contain any HTML elements such as or . The tag is placed in the document HEAD. The optional TYPE attribute is used to specify a media type--text/css for a Cascading Style Sheet--allowing browsers to ignore style sheet types that they do not support. Configuring the server to send text/css as the Content-type for CSS files is also a good idea.:
view source
print?

<link href="skin.css" rel="stylesheet" type="text/css"> 

A style sheet may be imported with CSS's @import statement. This statement may be used in a CSS file or inside the STYLE element:
view source
print?

<style type="text/css" media="screen, projection"> 
<!-- 
@import url(http://www.integralwebsolutions.co.za/style.css); 
@import url(/stylesheets/hunk.css); 
dt { background: yellow; color: black } 
--> 
</style> 

The important thing to remember, and something that will confuse many and getting running around in circles, is that style sheets are cascading. The load from the top down and the last style stipulated will be the style used. Also each style can build upon the previous one, but if you overwrite a previous property then the last one is used.

So the process generally is as follows. Your External style sheet is loaded, then any imported style sheets are loaded, then the Embedded style from the element is loaded, and finally in tag in-line styles are loaded. This then will be the final presentation of your page style.

Related Reading:

Cascading Style Sheets (CSS) II - Selectors

Cascading Style Sheets - Selectors III

Cascading Style Sheets (CSS) - III - More Selectors

Cascading Style Sheets – Selectors IV – Pseudo-Classes.

Cascading Style Sheets - Pseudo Elements

pimp it
Tags:
blog comments powered by Disqus
 
Blog Updates Via E-mail
 Blog Updates Via E-mail
Minimize

Do you want to receive blog updates via e-mail. Then just click on the link below. You will be redirected to Google's feed burner, where you can fill out a form. Supplying your e-mail address.

The subscription is managed entirely by Google's Feedburner. We cannot and do not collect your email address.

Subscribe to The Brave Programmer by Email

Print  
 
Win free advertising space for a week by just commenting on a blog post.
Latest Comments
 Latest Comments
Minimize
Powered by Disqus

Sign up with Disqus to enjoy a  surprise box of features

Print  
 
Blog Roll
 Blog Roll
Minimize
Print  
 

 

She's The Geek
Empowering Women Through Technology
<h1>Search Blogs From The Brave Programmer</h1>
 

Search Blogs From The Brave Programmer

Minimize
Print  
 
 Most read Blog posts
Minimize
Print  
 
Archive
 Archive
Minimize
Print  
 
<h1>News Feeds (RSS)</h1>
 

News Feeds (RSS)

Minimize

Fri, 30 Jul 2010 07:50:59 -0500

Thu, 29 Jul 2010 05:45:05 -0500

Wed, 28 Jul 2010 05:45:08 -0500

Tue, 27 Jul 2010 07:09:33 -0500

Mon, 26 Jul 2010 07:03:58 -0500

Sun, 25 Jul 2010 14:50:59 -0500

Thu, 22 Jul 2010 05:45:13 -0500

Wed, 21 Jul 2010 05:48:41 -0500

Tue, 20 Jul 2010 06:03:21 -0500

Mon, 19 Jul 2010 07:31:27 -0500

Print  
 
Contact Us Now
 Contact Us Now
Minimize
 

Email  us now or call us on 082-413-1420,  to host your website.

We design and develop websites. We develop websites that make a difference. We do Dotnetnuke Module development.

Grab The Bookmarketer For Your Site

Web Masters Around The World
Power By Ringsurf
Print