HTMLSource : HTML Tutorials<HTML Source="excellent"> |
---|
Home | Full Index | Site Info | Contact | Directory | Updates |
---|
Introduction to CSSby Ross Shannon
Reader's note: this is just a preview of our future HTMLSource 3.0 presentation. No doubt it'll be considerably sharpened before I get around to redesigning the whole site with it. Until then, if you have any comments or suggestions for what you'd like to see, please don't hesitate to * send them in.
The content below is for testing purposes - the real introduction to stylesheets can be found here. [ updates ] HTML was originally designed to be a simplistic way of presenting information, with the aesthetics of a web page being much less important than the content (and largely being left up to the web browser). Of course, now that the Internet has become as popular as it has, the presentation of your writing has become almost critical to a site's success. This, among other things, is why CSS was brought in. Page Navigation: What are Stylesheets? | Implementation · One central stylesheet · Individual style blocks · Using the STYLE attribute What are Stylesheets?Cascading Stylesheets, or CSS, are both the same thing. Over the last few years, coders, in their new position as designers, noticed that they were retyping the same old tags again and again on the same page, leading to bigger HTML files and above all, time consumption and frustration. You may have found yourself in the same situation, adding in mountains of Then, someone had a great idea - have one file that defines all the values that those piles of tags would have done, and then have all your pages checking this file and formatting your pages accordingly. You can therefore leave out many of the formatting tags in HTML and use only structural ones (like headings, paragraphs and links) - separating style and content. In late 1996 CSS became a reality. They claimed to be component of a webpage that would act as a partner to your HTML designs; taking care of all the layout, font, colour and overall look of your site. At first glance CSS seems primarily geared towards text formatting, but any tag can be used and redefined. If you ever decide to change the look, you modify that one CSS file (your style sheet) and all the HTML pages reading from that file will display differently. This makes maintenance of your design much easier. CSS's main boon however, is that you define things once, making it far more efficient than defining everything in HTML. This means pages download faster and you have to type less code, as your pages are shorter and neater. That, and there are dozens of powerful extra formatting options and possibilities available through stylesheet commands that are not possible through normal HTML. You'll see these later on when we get on to things like backgrounds, spacing, layers and borders.
Browser Compatibility Note:
Browsers began to support stylesheets properly at the version 4 mark. IE3 had some basic understanding, NN 4.7 is very glitchy, but » IE5 and » NN6 are now coming close to full compatibility, at least of the first level released by the » W3C (» CSS1). CSS2 and beyond are gradually becoming supported.
If the browser doesn't understand the CSS code, it will continue displaying the page ignoring it. Thus, you must make sure that your page is at least readable without it (a feature called graceful degradation). They are termed 'cascading' stylesheets because of two reasons: One stylesheet can cascade, or have influence over multiple pages. Similarly, many css files can define a single page. ImplementationThere are 3 ways to implement css commands into your site:
One Central StylesheetThis is the best way to use CSS, in my opinion. You write one css file and have all your pages referencing it. This way, a change to anything in this one file will adjust this thing (a font, for example) across your whole site. You could change your entire colour scheme with one modification if you want, over an unlimited number of pages. That's one of the things CSS was designed for - flexibility. To create your stylesheet, open a text editor (NotePad or SimpleText will be fine). Remember in the very first lesson on this site, you learned how to save from a text editor into the .html file format? Well, here you'll be doing roughly the same except your file will have a .css suffix. Just save a blank file as style.css and put it in the same directory as your homepage. Now that you have that, I can show you the command syntax used in CSS: And now a worked example: P {font-family: Arial, sans-serif; color: #0000FF; font-size: 12pt; } Just put that one line into your file for the duration of this tutorial. That's all you need. Having this style declaration in your css file would make all the text in your page enclosed in the This is how all the affected paragraphs will be formatted. Have a look over these guidelines:
You could add another line in under your first one. Try this line of CSS and then use some large headings on your page: h1 {font-family: Verdana, sans-serif; color: red; font-size: 20pt; } Your stylesheet should look 4 like this. Now that you have something in your file, you'll need to show your pages where their css file is. Put this line of code into the
Some common tags you may want to redefine are but you can change any tag you want. If you're looking for a list of CSS properties and values, look over » C-Net's Table of Style Sheet Commands. If you want to affect multiple selectors with the same CSS formatting, add them all together, with commas, like so: p, div, h1 {color: #00DDFF; font-weight: bold; } /* modifies all 3 main tags */ As above, you can also add comments to your stylesheet using the Java-inspired /*...*/ delimiters. These can give you or anyone else using your stylesheet vital tips about what's going on in your code. Individual Style BlocksIf you use a common design across all of your site's pages, you should be using the method above. What you should use this for however, is if all your pages are different, with different needs, you can put style commands specifically useful to that page in. To embed style, put this into your
Just put all your CSS between the comment tags. These are there to stop the code coming up as text on your page. The Using the style AttributeIf you need to modify one tag on its own you can embed style information into it like so:
The style formatting will stop as soon as you close the tag with the attribute ( Want to see what a stylesheet looks like? 4 Look at ours! (use Notepad to open) Keep Learning // CLASSes, IDs and SPAN > Go! Go!
Other Stylesheets Articles //
CLASSes, IDs and SPAN >
CSS and Text >
CSS and Links >
DIVs and Positioning >
Backgrounds and Spacing >
Named Colours >
CSS and Borders >
CSS and Scrollbars >
CSS and Cursors >
Non-underlined Links >
< Homepage | Full Index | Section Index > |
Starting Off Start Here · My First Site · Lessons Text · Images · Tables · Frames · Forms · Stylesheets · Javascript · Advanced Accessibility · Promotion · Optimisation · Source Network Earthsource » Questions? Comments? Suggestions? Complaints?
» We want them! More Resources ¤ Links» W3C's Style page These are the guys who invented and maintain CSS. Their site has all the information you could need about style. » C-Net's table of CSS commands A full list of available css commands. » Webmonkey: Mulder's Stylesheets tutorial An excellent all-encompassing CSS tutorial from one of the webmonkeys. » Alertbox: Effective use of Stylesheets How to implement stylesheets successfully, for maximum usability. Programs » Topstyle Lite This CSS editor comes with a built-in declaration lists, allowing you to add properties and values easily. Books » CSS Books Pop in to Amazon and pick up some books on Stylesheets. |
---|
> Homepage | ^ TOP ^ | © 2001 Ross Shannon |
---|