Current Articles
  Archived Articles
  TECHS Articles
  Current Projects
  About Us
You are not logged in.

Please either Login or create a New Account.
Custom RSS

Note: this links is the RSS feed for the current filters shown at the top of the page. For an RSS feed for all articles in this community, click here
Author
Adam Griebel (5)

CSS Lesson 1 of 4: What’s CSS and Why Do We Need It?

Cascading Style Sheets (CSS) is a powerful way to add styling and to control a web site’s appearance.

CSS was created to work along side HTML, however it is a different language compared to HTML. You can use CSS to control everything from the color of your text to how far apart elements are spaced on your page. CSS will also let you change the color and background of an element as well as adding borders to an element. It will even allow you to do more advanced stuff like popup windows. One of the real benefits of CSS is it allows web designers to separate the content from the presentation and have all of a site’s presentational information in one location.

The "cascading" in "cascading style sheets" is basically the order of precedence that the browser uses to apply style rules. If there are any conflicting declarations, the cascade is the process that sorts it all out and determines which rule will finally win. In other words, the style rule with the highest precedence is the one that is used. One of the simplest forms of precedence is that the style that has been declared last on the page is the one that will be applied – that is, if all other things are equal.

Now that I have given you a brief synopsis of what CSS is, let’s talk about why we need it. In the beginning, well before CSS at least, HTML was used to control the presentational aspects of a page. With web sites becoming increasingly complex, a majority of the code merely determined the appearance of a web site. While this did not create any problems for the end user, it made web site maintenance especially difficult and time-consuming. For example, to change the color of your links, you would need to go to each and every link and change it manually.

So in 1995, the World Wide Web Consortium (W3C) began working on a solution. By 1996, the W3C came up with, you guessed it, CSS. Using CSS to move the presentational information out of the HTML document not only makes web sites easier to update and maintain, but it also has several other benefits, such as cleaning up the code, making the web sites easier to be indexed by search engines, and making websites more compatible with screen readers. CSS also gives you more options and can make a much richer looking web page than HTML ever could.

Resources for CSS Class
Rock Paper Scissors Demo
RockPaperScissors.zip
lesson4.zip
Pixie (Windows Only)

Notes for Mac Users: If you are having trouble using "TextEdit" to view the code of the HTML files, open up the preferences of TextEdit and under "Open and Save" make sure "Ignore rich text commands in HTML files" is checked.

Instead of using Pixie to grab the hex value of a color you can use the Digital Color Meter in the Utilities folder in Applications.  Select "RGB As Hex Value, 8-bit" from the drop down list in Digital Color Meter and when you are over a color you like do a shift-comand-c to copy the value to the clipboard. For some reason when you paste the hex value it has quotation marks around it so don't forget to remove them.  

Some Great Websites to Learn More About CSS
The W3C CSS Home Page
W3Schools CSS Tutorial
Zen Garden



Tags: CSSTECHS




CSS Lesson 2 of 4: CSS Placement

CSS can be placed in three different places in your web site. First, it can be placed in-line within an individual element. Second, it can be inserted at the top of a single web site page. Lastly, it can be in an external CSS file.

In-Line Style
The easiest way, although probably not the most recommended way, to add a CSS style to an element is to put it directly in the tag. You can add an in-line style to any HTML tag as long as it is within the BODY tags of your page. For example, if you wanted to make all of the text within a div tag red, you would do the following:

<div style="color:Red;">Hello there.</div>

You just want to make sure that you do not forget your semi-colons and quotation marks. One thing to note here is that in-line style declarations will get the highest precedence in the cascade and will be applied over any other conflicting rules. Like I said, this is not considered the best way to set a CSS style to a tag. It is little better than the old way of just using basic HTML. Setting all of your styles this way would make your code harder to read and even harder to maintain. But there are times when it can be very handy, especially when creating a web site and you are troubleshooting a particular CSS error or when you want to apply a style quickly so you can see how it looks.

CSS for One Page
If you just want your CSS rules to affect one web page, you can put your CSS all in one location in the HEAD of your document. All you need to do is use the style tag in the head of your web page. The following example tells the browser to show any text within an element that has the class "blue-text" with a blue color and to show any text within an element that has the class "red-text" with a red color.

<head>
    <title>my awesome webpage</title>
    <style type="text/css">
         .blue-text { color:Blue; }
        .red-text { color:Red; }
    </style>
</head>

Site-Wide Style Sheets
The third and most common way to add CSS to your web page is to use an external file with all your CSS rules in it. There is nothing really all that special about the CSS file itself. It is just a plain text file with an extension of .css. You just need to make sure you remember to tell your web page where the CSS file is by adding a link tag in the HEAD of your web page. In your link tag, just make sure you include rel="stylesheet". By the way, "rel" stands for relation. Make sure to set the type to text/css. This is very important because it tells the browser how to import the data.

 <link href="/default.css" rel="stylesheet" type="text/css" />
Tags: CSSTECHS




CSS Lesson 3 of 4: CSS Structure: Part 1


CSS Lesson 3 of 4: CSS Structure: Part 2

A CSS statement or “rule” has two main parts:  the selector and the declaration.  Let's take a look at the selector first.

Element Selectors
There are several different types of selectors.  The most basic type of selector is the HTML element itself.  This allows you to easily apply a set of rules to a certain element type all at once.  For example, if you wanted to make all of the text within a H1 blue, you would do the following:

h1 { color:Blue; }

You can even use two or more elements at the same time as the selector.  You just need to separate them with a comma.  There is really no limit on how many selectors you can have.

h1, h2, h3 { color:Blue; }

Class Selectors
Another way to apply styles to elements is to use the class selector.  Instead of having an element name as a selector, you use a class name preceded by a period.  The period must always be used before the class name because that is what marks it as a class selector.  Using a class selector is probably the most common and beneficial way to add styles to a web site as it enables you to be more selective on which elements the style is applied to.  To use a class with a certain element, simply set its class attribute to the name of the class.  In fact, you can even set several classes to a single element.  Just make sure you have a space between the different class names.  And don't forget that CSS class names are case sensitive.

<html>
    <head>
        <style type="text/css">
            .blue-text { color:Blue; }
        </style>
    </head>
    <body>
        <div class="blue-text">
            This text is blue.
         </div>
     </body>
</html>

ID Selectors
ID Selectors are used a lot like the class selectors but there are a few differences.  Instead of using a period like with the class selectors, you need to use a pound (#) sign, or as I like to call it, the little itty-bitty tic-tac-toe sign.  To use an ID selector, you use the ID attribute of the element.  Unlike classes, IDs can only be used once per page since IDs have to be unique for that HTML page.  Also, don’t forget that just like classes, ID selectors are also case sensitive.

<html>
    <head>
        <style type="text/css">
            #blue-div { color:Blue; }
        </style>
    </head>
    <body>
        <div id="blue-div">
            This text is blue.
         </div>
     </body>
</html>

The Declaration
The correct syntax for a declaration is a property followed by a colon and then a value followed by a semicolon.

h1 { color:Blue; }

In this example "h1" is the selector, "color" is the property, and "Blue" is the value.

One thing to note is that syntax is very important when writing out your declarations.  If you make a mistake or have an invalid declaration or keyword, then the whole rule will just be ignored.

Just like you can group selectors together to make a single rule, you can also group declarations together into a single rule.

h1 { color:Blue; font-family: Arial, Helvetica, sans-serif; font-size: 13px; }

This is definitely the preferred way of defining multiple styles for a single selector.  Just remember to put a semicolon after each declaration.  While it might be valid CSS to leave a semicolon after your last declaration, it is generally not considered good practice and I wouldn’t recommend it.
Tags: CSSTECHS



In this lesson we will write a simple 2 column layout using CSS.

Here is the source code for the demo: lesson4.zip
Here is a link to the color picker program (Windows only): Pixie

Mac users: instead of using Pixie to grab the hex value of a color you can use the Digital Color Meter in the Utilities folder in Applications. Start it up and select "RGB As Hex Value, 8-bit" from the drop down list. Then when you are over a color you like do a shift-comand-c to copy the value to the clipboard. For some reason when you paste the value it has quotation marks around them so don't forget to remove them.


CSS Lesson 4 of 4: Let's Write Some CSS Already!: Part 1


CSS Lesson 4 of 4: Let's Write Some CSS Already!: Part 2


CSS Lesson 4 of 4: Let's Write Some CSS Already!: Part 3


CSS Lesson 4 of 4: Let's Write Some CSS Already!: Part 4


CSS Lesson 4 of 4: Let's Write Some CSS Already!: Part 5
Tags: CSSTECHS



While growing up in the small town of Sargent, Nebraska, I knew early on that I wanted to be a programmer and spent most of my free time working on computers and electronics. In fact, the first computer I ever programmed on was an Apple IIe using BASIC. It wasn't easy being the smartest kid in school, but I really think it prepared me for working with my co-workers, Nate and Brian. It taught me patience in dealing with those less gifted intellectually. My current position as one of the three .NET programmers at ESU 10 has afforded me the opportunity to work on a variety of websites, which have been challenging each in their own way. Whenever I have free time, I enjoy photography, reading, gaming, programming, creating and maintaining websites, and spending time with my wife Janae and our son Aiden.
Tags: bio



  1