CSS STYLE SHEETS

Boy, did this scare me at first. CSS — Cascading Style Sheets. Got to be a name one of the ‘techies’ thought up. Don’t you think?

Sounds like a cascading waterfall that builds up speed and power the further into it you go until… whoosh you’re buried in a 100-foot waterfall!

But don’t let it fool you. CSS makes your job easier. Trust me, it really does. Let’s add some style right now, OK?

(Just in case you want to READ about CSS
here’s the developers reference.)

When you read a book you’ll notice that the first line of a paragraph is usually indented. Until CSS came along, there was no simple way to do this on web pages. 

If you’d like to indent the first line of your paragraphs, just paste the following into the HEAD section of your page or add the middle line of code to your linked stylesheets: 

<style type=”text/css”> 
<!– 

p { text-indent: 2em;} 

–> 
</style> 

 

HIGHLIGHTING

With CSS you can highlight text on a page, making it look like you ran a yellow highlight marker over it. This is great for emphasizing important words or points. 

Just add this code to the HEAD section of your HTML page: 

<style type=”text/css”> 
<!– 

.HL {background: #ffff99; 
color: #000000;} 

–> 
</style> 

What you’ve done is create a CSS class, and now the table is set. To use it to highlight a passage, you could write: 

<font>this is highlighted</font>

The words “this is highlighted” will have a yellow background with black text. Of course, you can change those colors to anything you want by modifying the colors in the CSS code. 

Let’s not stop there. OK? What about if we wanted to highlight an entire paragraph? If you don’t like messing with tables, try this style tag: 

<P style=”background-color: FEE333″;> 

All of the text in the above paragraph will be highlighted in yellow-orange. To change that color, just substitute any other hex code or use a color name. 

This CSS tag works in both Netscape and Internet Explorer. 

SPACING FOR LINES & PARAGRAPHS

Sometimes the designer (YOU) doesn’t want so much space between paragraphs. (Like when using bullets or such) You can control the space between paragraphs — and lines — like this:

You can set the line height for paragraphs with a little CSS in the HEAD section of your HTML document, like this: 

<style type=”text/css”> 
<!– 
P {line-height : 12px;} 
–> 
</style> 

Just change the “12px” to however many pixels you need it to be. The comment tags should be included to prevent crotchety older browsers from displaying the code. 

You can set the line height for paragraphs with embedded style sheets — CSS in the HEAD section of your HTML document — like this: 

<style type=”text/css”> 
<!– 
p {line-height : 20px;} 
–> 
</style> 

Just change the “20” in 20px (pixels) to the number you need. 

You can also place the CSS code right in your HTML tag, as an inline style. 

<p style=”line-height: 20px;”> 

Both methods accomplish the same thing. The advantage of embedding them in the HEAD section is that the line height will be applied every time you use a <p> tag. With the inline style, you have to insert the CSS code into each paragraph 

Now let’s see what it looks like, both in CODE and diplayed in the browser. 

 

CSS UNDERLINE/OVERLINE LINKS

There are some very cool ways to handle links in your page. Here’s one that uses the CSS to make your links look different. Just try underlining AND overlining them, framing them between horizontal lines. Just add: 

<style type=”text/css”> 
<!– 
A:hover {text-decoration:overline underline} 
–> 
</style> 

to the HEAD section of your page. The underline and overline will display whenever a visitor moves the cursor over the links. 

A variation: If you remove the word “underline” from the above code, the link will be underlined (with no overline) at rest, and overlined (with no underline) when a visitor’s cursor is hovering over it. 

<style type=”text/css”> 

<!–
a:hover{color:ff0080; background-color:ffff00;}
–>
</style> 

 

FORM ELEMENTS

There is a lot you can do with CSS. Here’s an example of CSS working with form elements. Form elements can be a bit boring…so we’re going to liven things up a bit.

Let’s first start with a simple head tag that will color all the elements in a text field box.

 

BUTTONS

Now what about those awful looking buttons? First let’s change the shape… 

<input type=”reset” value=”Reset” style=”width: 80px;”> 

Just reset the pixel number to whatever you like as long as it’s larger than the text.

We can take it a step further in IE and add effects to the boxes:

Cut and Paste this into the <Head>

<STYLE>
.bigChange {color:blue; font-weight:bolder; font-size:175%;
letter-spacing:4px; text-transform: uppercase; background:yellow}
.start {color:yellow; background:navy}
</STYLE>


function highlightButton(s) {
if (“INPUT”==event.srcElement.tagName)
event.srcElement.className=s
}

And this into the body:

<FORM NAME=highlight onmouseover=”highlightButton(‘start’)”
onmouseout=”highlightButton(”)”>
<input type=”button” Value=”Pass your mouse over me”>
</FORM>

Now on to the final CSS trick. Are you still with me? Good.

** CSS LINK MENU **

We’re going to create a menu using CSS only. Awesome stuff here. I won’t take up space here to list the code. Just look at it in the popup window and copy the code from ‘view source’.

Let’s move on to more dynamic uses of code. Are you game?

 

Advertisements