Forum Moderators: not2easy
Hi everyone, I'll be running a series of crash course, hands
on CSS tutorials over the next couple of months as many members
still have yet to break the ice with stylesheets. And more than a few have made it part of their New Years Resolutions! [webmasterworld.com]
You will find the index to CSS Crash Course here [webmasterworld.com].
What will you learn?
The course will be very much a practical, hands on guide, with links to
further reading and information. We'll take a simple XHTML Document [webmasterworld.com] and
gradually turn it into a presentable web page whilst learning the basics
as we go. For example:
You're invited to discuss the course and please point out any missing or
complimentary information. er... and mistakes of course ;)
Browser support
All of the stuff we'll be discussing in this and the next part of the course (font control), is well supported by the major browsers, including NN4. Where an exception to this occurs, I'll let you know. If you spot something I miss, let me know...
Essentially, CSS is the preferred way of styling HTML elements. That
includes colors, fonts, positioning and other presentational
aspects of n web page.
HTML was not originally designed to handle the presentation of web
pages, just the structure of hypertext documents. By the time
we got to HTML 3.2 though, both Netscape and Microsoft had added a whole
bunch of new and sometimes proprietary tags and attributes to the
original specification.
Prime examples would be the <font> tag, the color attribute and the
annoying <blink> tag. None of these are supported in current XHTML specs.
The consequences and legacy of HTML 3.2 still
haunt us now, we surf a web of pages that are bloated, display poorly,
and in extreme cases are downright butt ugly.. Not to mention the
fact that the majority of pages that are written using this kind of code
are an accessibility nightmare.
All is not lost!
In December 1996, almost exactly a year before HTML 4.0 was released, the World Wide Web Consortium [w3.org] answered this progressively worsening problem with StyleSheets!
The basic idea behind CSS is to outsource the presentational elements of
an HTML document, leaving us with neatly structured, semantically sound
markup and content.
This allows the document to be shown on a wider
variety of devices and media and gives people with special requirements
such as the blind or physically handicapped greater control over how
they interact with the vast amount of information available on the net that most of us take for granted.
The Cascade
A key concept in the CSS ideal is the cascade, You can have many
different styles that relate to a document specified in a number of
ways. The key thing to remember is that all styles, however specified,
become part of one big stylesheet. Conceptually at least.
They rank in this order:
We had a great discussion on Using the Cascade, here.. [webmasterworld.com]
Three Main Ways To Implement Styles
From the above list you'll see that there are three ways that we, as
html authors, can influence the way our documents are presented: Inline,
Inside the <head>, and externally. Here's a brief look at each method:
Say we want all our <p>aragraphs to be in verdana (we'll get to
specifics later...)
Inline Styles
[pre]
<p style="font-family: verdana, arial, sans-serif;">
This paragraph should
be in verdana. If verdana is
not installed on your machine
it will be in arial or a sans-serif font.</p>
[/pre]
Inside the <head> of your document
[pre]
<head>
<title>Inside the head of your html</title>
<style type="text/css">
p {
font-family: verdana, arial, sans-serif;
}
</style>
</head>
[/pre]
External styles
From both a clean code and SE friendly perspective the external
stylesheet is a true knight in shiny armour! Here's how it works:
[pre]
<head>
<title>The External StyleSheet</title>
<link rel="stylesheet" type="text/css"
href="/path/to/styles.css" />
</head>
[/pre]
[pre]
<style type="text/css">
@import url(path/to/styles.css);
</style>
[/pre]
[pre]
/* styles.css *//* You can add comments like this
on as many lines as you like both in external sheets and styles defined
in the <head> */p {
font-family: verdana, arial, sans-serif;
}
[/pre]
If you're not, don't worry! We'll go over this with practical examples in the next part of the course.
For the sake of ease of explanation we'll use styles in the <head> of the
document for the examples that will follow this introduction but,
external styles are certainly the way to go if the rules you set are to
appy to more than a couple of pages in your site.
Well, that's the boring bit over ;) - Next time we'll take a look at Font Control and Selectors and introduce the sample document we'll be working with.
See you there...
Nick
[edited by: Nick_W at 10:31 pm (utc) on Dec. 17, 2002]
Season greetings and all that feel good spirit thing.
Jolly good show.
I've been into CSS two years now, and ALL I have learnt came from research beginning with Dave Raggett's intro to CSS, and one other person whom I contacted earlier at that time.
I remember it had something to do with this <\/>. At the time I thought it was a V but how wrong was I. Forward slash \ followed by a backward slash / because of CSS' schema.
After that I was on my way. All I did from thereon was to test, test and test every thing again. Eventually it sank in and everything came naturally.
As of the moment I am trying to move away from tables, but because of the different page lengths, I'm having to make changes to adjust for footers. It is a challenge to try and make a template where I could just insert it at the bottom of each and every page page and have it displayed exactly in the browser as I want it.
I don't intend to superceed the step by step class, but if you can send me a sticky on the layout I'd be very gratefull. Did some research on BOX but still nothing concerning my intended layout.
By the way, from what I read It appears a page designed by CSS 3 schema, may not render properly by all current browsers. I'm praying this will not render my layout ineffective. In the meantime I have only one page online just to be sure until I have tested and have seen the end result across all available spectrum, before I upload the others I'm working on at the moment.
I have flagged this subject and will be following the course because I know I still have much to learn. I hope others will follow the course as you proceed. This is a very valuable hands on step by step instruction and I'm sure everyone will appreciate the home work you did and kind enough to share it with all of us.
Jaybee
does this mean that I can link a main style-sheet to a page, and have different other style-sheets imported in the main style-sheet?
Yes, but check out this thread:
[webmasterworld.com...]
Question: what is the difference between link rel="stylesheet" and @import url?
Actually, I think the lack of difference between the two is a function of a currently universal bug in CSS support than correct behavior. I haven't found it in the official specs yet, but I trust my O'Reilly book when it tells me that although multiple <link>ed stylesheets will be cascaded by any currently available browser, the correct behavior would be to offer the user a choice amongst the available <link>ed sheets, ignore the others, and continue the cascade from there. For that reason, on pages where I'm after the cascade, I may <link> the first sheet in the cascade, but anything I want to follow that is @imported.
It allows you to have a special style sheet just for the older, css-challenged browsers, without requiring a separate page or any js.
I don't know whether it validates, but it works.
> Someone told me it was good to put your styles in your html as comments. is that a good idea?Think that someone is confusing it with JavaScript. Anyone know anything about that?
Also, it is possible that if you try to validate a top-of-the-page style sheet in a xhtml document, that something inside the style sheet might not validate unless it's enclosed in comments. The contents of the <style> tags are not html. I can't think of an example off the top of my head that won't validate, but there could be something.
It should be used like this:
<html>
<head>
<style>
<!--
body {color: black}
-->
</style>
</head>
<body>
...
</body>
</html>
For backwards compatibility reasons, browsers are supposed to treat the content of comments inside <style> and <script> tags as things they should parse. It's a terrible kludge, but necessary to keep older browsers rendering pages okay.
Part one is great!
Thanks!
Be sure to read Marcia`s WebmasterWorld Welcome and Guide to the Basics [webmasterworld.com] post.
Did you see the CSS Crash Course - Index - Menu for the WebmasterWorld CSS crash course [webmasterworld.com]?
There are two more parts to read :)
Andreas
You're most welcome, if you missed it, the index is here: [webmasterworld.com...]
Nick