| what is code? |
top ↑ |
|---|---|
|
"code" is some text or characters that a program uses,
but a person doesn't see.
Your web browser is a program, that uses the html code to know
how to display the text and pictures.
When you look at your web page in the browser,
you see the results of the |
|
| what is a "text editor"? |
top ↑ |
|---|---|
|
A text editor is a program like Notepad – or better, Notepad++ or some other good text editor. It edits only the text, the characters, of your file. A program like DreamWeaver or Front Page is NOT a text editor. It is a website building program. If you write your web pages in the "code view", it can be very useful for making your web pages. But be sure to look at your pages in a real web browser — you may find that they don't look the same in the program "display view" as they do in a real web browser!
Programs like Microsoft Word or Open Office Writer
cannot be used for making web pages.
It definitely NOT a text editor.
It is a word processor:
It has hidden codes in the file, and your web page
won't work if you make it with Word or OOffice.
In fact — if you open a Word ( |
|
| what is a "web browser"? |
top ↑ |
|---|---|
|
A "browser", or "web browser" is a program on your computer that displays web pages. MicroSoft Internet Explorer is one web browser program. Another browser very popular these days is Mozilla Firefox. (Firefox is the most useful browser for developing web pages.) Other browsers are Opera, Konqueror, Galeon, lynx. There are even web browsers that do not display the page the way you are used to seeing it: For blind people, there are browsers that speak the page, or create the page in braille. Mobile phones or PDAs have browsers that make a special small size of the page to fit on their small screen. 'lynx' is a browser which is text only - it does not display images, movies, etc. |
|
| what is "CSS"? |
top ↑ |
|---|---|
|
"CSS" is code that tells a browser how to display the web page — it tells what the web page will look like. The letters stand for Cascading Style Sheet The Styles will Cascade, or flow down like a waterfall, from your styleSheet, to the head of the web page, to the inline style, to the default style of the html tag. |
|
| what is the minimum code that a web page should have? |
top ↑ |
|---|---|
|
At the very least, your page should have the codes you see in
this template
|
|
| Where do we put the CSS code? |
top ↑ |
||||||||
|---|---|---|---|---|---|---|---|---|---|
|
We can put the CSS code in three places:
In the sample code in these tutorial pages, i will be showing the css as in example 3 above, as in a stylesheet. This is how we do when we make real websites. But it is also useful when you are just trying things out in a web page, to use the first two ways, as in examples 1 and 2. |
| Why do we use these different places? |
top ↑ |
|---|---|
|
They are all useful!
|
| The parts of the CSS language: What is a “ruleset”? “selector”? “declaration”? “property”? “value”? |
top ↑ |
|---|---|
All of these parts are used in the head <style> tag or in the separate stylesheet:
↓---------------------------------- ruleset ----------------------------------↓
When we say:
p,
has two properties: color and font-size.
The value of color
is #cc0000, and
the value of font-size
is 90%.
When we use style in a tag in our html page, then we use only descriptors:<p style="color: #cc0000; font-size: 90%;> |
|
| class and id |
top ↑ |
|---|---|
|
If you want to have some different style for a tag, you can put the css code in the <head> of your page, or in a separate stylesheet, and give the element (tag) a name (the "class" or the "id"). Then you call that name in the tag in the <body>. |
|
what is a "class"?In this example, the name of the class is "first". In the style, we use the '.' to say that it is a class.
In the html, we "call the style" by saying
More than one tag in the html can have the same class. More at: |
<!DOCTYPE html />
<html>
<head>
<title>
My CSS Web Page
</title>
<style>
p.special {
color: #cc0000;
font-weight: bold;
}
</style>
</head>
<body>
<p class="special">
CSS may seem confusing at first,
but the idea behind it is similar to html.
</p>
<p>
It has codes that tell the browser
how to display things.
</p>
<p class="special">
We can use the same class
more than one time in a web page.
</p>
</body>
</html>
And this will make a web page that looks (more or CSS may seem confusing at first, but the idea behind it is similar to html. It has codes that tell the browser how to display things. We can use the same class more than one time in a web page. |
what is an "id"?In this example, the name of the id is "projects". In the style, we use the '#' to say that it is a id.
In the html, we "call the style" by saying
Only one tag in the html can have this id. More at: So why do we have both "class" and "id"?The purpose of both "class" and "id" is to name a tag so you can give it a special style. We use "class" when we want to style the same tag the same way, several times in a page. We use "id" when we want to style one tag a special way, once in the page. so Then "id" can be used for other things also:
In these cases, there has to be only one. |
<!DOCTYPE html />
<html>
<head>
<title>
My CSS Web Page
</title>
<style>
h2#projects {
color: #cc0000;
font-weight: bold;
}
</style>
</head>
<body>
<h1>
About our work
</h1>
<h2 id="projects">
Our projects
</h2>
<p>
Here is information about our projects.
</p>
<h2 id="more">
More about ids
</h2>
<p>
We can have more than one id for an element,
but we use each id only one time in a web page.
</p>
</body>
</html>
And this will make a web page that looks (more or About our work Our projects Here is information about our projects. More about ids We can have more than one id for an element, but we use each id only one time in a web page. |
| Doctype |
top ↑ |
|---|---|
|
The web browser has directions built into it, that tell it how to display the html and css codes. These directions tell it how to put together the html and css, according to what kind of "document type" the html page is. If the page has no document type, the web browser will decide for itself — and the page may not look the way you want. So always put a document type at the very beginning of all your web pages, before the <html> tag. These days the most useful doctype is this one: <!DOCTYPE html> "View source" of this web page, or see this page template, to see where to put the doctype. |
|
| Units of Measurement in CSS |
top ↑ |
|
|
| Why is it called “cascading”? |
top ↑ |
|
The web browser first looks at the stylesheet.
So direction flows from stylesheet, to head, to tag style, to html, kind of like a waterfall flows, or cascades, down the hill. |
|
| Does CSS work the same in all browsers? |
top ↑ |
About browser compatibilityYou have probably noticed already that some things don't look the same in Internet Explorer as they do in FireFox. Or in the display view in DreamWeaver. It can be pretty frustrating! Standards for the CSS language are decided on at the World Wide Web Consortium, an association of many companies and organisations concerned with the web. However, some of these companies do not follow the standards when making web browsers! But don't give up. The companies are improving rapidly. While we are waiting for them, there are ways to work with this. You can use javascript to detect what browser is being used, and then serve up a stylesheet customised for it. But — then new versions of the same browsers change and you have to keep up with them! In my opinion it's really not worth it. Stick with the simple things that work in all browsers, and spend your time on the important thing that keeps people coming to your website: its content!
For the times when we just have to do a certain thing,
search on the web for the words
|
|
| Your standard page template |
top ↑ |
About page templateSince there is a lot of page code to type, it is probably not useful to keep typing the same code every time (and make mistakes while typing!) More practical is to make a file with no content, and copy it to make our pages. Here is a suggested page template. |
|
| Could you please say all this in English? Or at least some language that i can understand? |
top ↑ |
|---|---|
|
The thing about all this is: CSS is a language. And talking about it is a language too, technical language. Just like any other language, at some point you have to just jump in and learn the new language and use it! In the meantime, i am trying to make this as clear as possible to help you wade in a little before you jump. Suggestions are welcome! |
|
| I see many other things in stylesheets on other websites. What are they? Why aren't you showing them in the CSS Tutorial? |
top ↑ |
|
Yes, there are many more things possible. I'm trying to keep this introduction simple to get you started, and to show you how to learn. Then you can learn more things the same way i did: by finding them on the web, and trying them out! |
|
| What if i make mistakes? |
top ↑ |
|
If you make mistakes, you are learning things!
If you don't make any mistakes, either
Don't worry, you can't break anything. You will learn things.
make many misteaks. learn lots.
Take risks: If you win you will be happy; if you lose you will be wise.
|
|
| Where can i learn more? |
top ↑ |
|---|---|
|
|
| copyright / license |
top ↑ |
|---|---|
|
Q: Can i copy this file? Can i give to other people? Answer: Sure, you can give it to anyone, according to the terms of the license below. It is copyright © 2004 James Walker. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included here. If not found, find it at www.fsf.org - the Free Software Foundation. |
|
| translation |
top ↑ |
|---|---|
|
It would be very useful to have translations of this document in any language. Most preferred would be Tibetan and Chinese. Please contact me if you can do a translation for us. |
|
| contact |
top ↑ |
|---|---|
|
Was this helpful? Is it clear, or confusing? I would be happy to hear anything about how to make this better. You can contact me at the email address i have given you, or at http://www.webwalker.to/contact.php |
|