HTML Blox

Providing the building blox of the web.

  • HTML Blox Home
  • Blog
    • Design
    • Flash
    • General
    • HTML
    • Javascript
    • PHP
    • Programming
    • Web Servers
  • Forums
  • Where to Start?
  • Lessons
    • CSS
    • Design
    • HTML
    • Javascript
    • Programming
  • References
    • HTML
  • Resources
  • About
  • Contact
  • Go Green!

CSS Lessons

  1. Lesson 1: The Basics
  2. Lesson 2.1: Dimensions - Units of Measurement
  3. Lesson 2.2: Dimensions - The Properties
  4. Lesson 2.3: Dimensions - Borders
  5. Lesson 2.4 - Dimensions: Adding It All Up
  6. Lesson 3: Colors
  7. Lesson 4.1: Layouts - Floating
  8. Lesson 4.2: Layouts - Absolute Positioning
  9. Lesson 5.1: Background Basics
  10. Lesson 5.2: Backgrounds - Picturesque Backgrounds - The Pieces
  11. Lesson 5.3: Backgrounds - Picturesque Backgrounds - Putting it Together

CSS Reference

  1. No reference yet.

Links

  • W3C HTML 4.01 Strict Compliant
  • W3C CSS 2.1 Compliant
  • Web Standards Group Member
  • Follow us on Twitter
  • Number Overflow - Free Advanced Scripts and Tutorials
  • Azure Ronin Web Design - Professional Web Design and Development
  • XML Sitemap
  • U Comment, I Follow

Feeds

  • RSS 2.0 Feed
  • RDF/RSS 1.0 Feed
  • RSS 0.9 Feed
  • Atom Feed

Lesson 1: The Basics

del.icio.us Digg Blinklist reddit

Websites consist of many different technologies. The basis for those is HTML, which provides websites their structures. The compliment of HTML is CSS, which provides the design and look of the website.

What is CSS?

CSS stands for Cascading Style Sheets. The Style Sheet portion refers to the fact that this is a “sheet” (or document) which tells the browser how to style the HTML. The Cascading part refers to how CSS behaves in that if you set a property, like color or text, for a parent, it cascades down to each of that parents children, grandchildren, and so on.

The Basic Syntax

The basic syntax of CSS is fairly simple. You first state which element or elements you are going to affect with the specific block of CSS. Then, you place an open curly bracket ({) and after that you add each of your statements, starting with the elements to be affected, then a colon (:), then the parameters for the statement, followed by a semi-colon (;). You repeat this for each statement you want for this block, then you end the block with a closing curly bracket (}). Here are a few examples:

Code

body {
  background: #F0F0F0 url(back.png) top left no-repeat;
  color: #333;
  padding: 0;
}

a .external_links {
  text-decoration: underline;
  color: #66FF32;
}

#content > div {
  padding: 1em 2em;
  border: 2px solid black;
}

Three Ways to Specify

There are three ways you can specify any specific elements by. The first is the element name itself, like body or p (for paragraph). When you specify like this, it will effect every element of that type.

Another way is to specify it by class. To do this, you would set the class attribute of each of the elements which you want to affect. Then, in your CSS you specify it by placing a period (.) and then the class name you gave the element. Note: Don’t put the period in the class attribute; only put the period in the CSS.

The last way to specify is by id. On any given page, there can only be one element that has a specific id. You specify the id attribute of the element you want to affect, and then in the CSS you place a pound sign (#) followed by the id name.

Since this is cascading style sheets, you can also select elements based on their parents. There are a number of ways to do this, and we will cover them all in-depth in a future lesson, but their basic syntax is simply stringing them together one after another, separated by special symbols (if needed) which cause it to react in various ways. Here are a few examples of the element name chains:

Code

  body > div {}
  p a {}
  h1+p {}
  a~img {}

Additionally, you can also have the same block of code affect multiple things by separating the names with commas. Here is an example:

Code

p, a, li {
  color: #F00;
}

That block would set the font color of all paragraphs, anchors, and list items to be red.

One final bit of basic syntax is comments. You can place comments in your code which are basically little notes to yourself about what each chunk means. To create a comment, you start with a slash followed by an asterisk (/*). You than type whatever you want, on as many lines as you want, and when you are done, you put another asterisk and another slash, in reverse order of the first (*/).

Here is a quick examples:

Code

/* The following makes the background color blue. */
body { color: blue; }

In our next lesson, we’ll start taking a look at how to manipulate sizes and positions of our elements which will lead into how to arrange our divisions and spans to create our layouts: Lesson 2.1: Dimensions – Units of Measurement

If you haven’t, go ahead and read through at least the first several HTML lessons as we will be referring to many HTML elements throughout all of these lessons.

This entry was posted on Tuesday, August 5th, 2008 at 1:27 pm and is filed under CSS Lessons. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

Please Login or Register or fill out the following to leave a reply:

If you haven't posted an approved comment before, your comment will not show up until approved.

  • HTML Blox Home
  • Blog
  • Design Blog
  • Flash Blog
  • General Blog
  • HTML Blog
  • Javascript Blog
  • PHP Blog
  • Programming Blog
  • Web Servers Blog
  • Forums
  • Where to Start?
  • Lessons
  • CSS Lessons
  • Design Lessons
  • HTML Lessons
  • Javascript Lessons
  • Programming Lessons
  • References
  • HTMLReferences
  • About
  • Resources
  • Contact
  • Go Green!
  • Sitemap

Copyright © 2008 HTML Blox

Unless otherwise noted, all images created and copyright HTML Blox.

Operated by Azure Ronin Web Design