Introduction to CSS
Welcome to Cascading Style Sheets (CSS) : An Interactive Tutorial for Beginners. With the help of this hands-on CSS tutorial, you can learn virtually every aspect of CSS1, by example, according to the official W3C specifications.
Imagine you've just designed a two hundred page web site for a client (or maybe for yourself) but at the last minute your client (or you) decide the font is a little two small or the typeface should be serif instead of sans-serif? You didn't know how to use cascading style sheets (CSS) so you coded all of the pages with the old-style tag. If you didn't know CSS, chances are you'd have to replace every occurrence of the old tag with the new tag. But if you had decided to write the site with CSS from the get-go, all you would have to do is replace one single line of code in a master file, and your entire site would be rendered immediately in your new style.
That's just one file to upload. That's a lot better than two hundred. Now you can do other things with your time. This is one major reason cascading style sheets are important. CSS makes web site maintenance easier.
Basics of using CSS Styles
To start off our understanding of cascading style sheets, we're going to use a special line of CSS code that does something HTML alone could never do right… we're going to indent every paragraph automatically.
Here's the CSS code:
p { text-indent: 3em; }
As you can imagine, in its current form, the code does not but display p { text-indent: 3em; } on the screen instead of changing the way the paragraph tag behaves. We have several choices to implement this as an actual style, all of which are covered in this chapter:
- Write it inline inside each and every tag
- Place a at the beginning of the web page
- Dedicate and link a CSS file and write it inside that file
- Use @import to include it as portion of a page's CSS
Writing inline style inside each tag is one of the worst ways to design a CSS page, although there are a few rare circumstances where it may be appropriate. But to know CSS, you need to know how to do it, and it will also help you understand how the CSS system works.
In our example, p is the selector, that is, what is selected to follow your chosen style. What the web browser understands is that when it sees the tag p, before writing any content, it needs to indent the text 3em. (1 em is a size for laying out glyphs in print... the important thing to understand about 3em is that 3em is about 5 spaces, the typical indentation choice).text-indent is a property, and 3em is the value of that property.
All definitions in CSS follow this format:
selector { property: value; }
No comments:
Post a Comment