This is a discussion on CSS Tutorial - Beginners within the HTML, DHTML and CSS forums, part of the Programming / Scripting / Coding category; CSS for Beginners This CSS tutorial is aimed at people who already have a decent knowledge of HTML, and want ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| | #1 (permalink) |
| Newbie | CSS for Beginners This CSS tutorial is aimed at people who already have a decent knowledge of HTML, and want to begin to learn CSS (Cascading Style Sheets). If you do not currently know a great deal of HTML, I would advise searching for some tutorials on these forums, or you can begin at W3Schools. 1. What is CSS? What does it do? CSS is an acronym for Cascading Style Sheets. These 'sheets' are implemented into HTML pages and provide an easier, more efficient and more powerful way of displaying information, using complex and more customizeable layouts, and also providing a semi-interactive basis, of which can be manipulated further with JavaScript (otherwise known as DHTML (Dynamic HTML)). The following tutorial will be based around the first two of these: display and layout. When first starting with CSS, many people can get confused about how it is used - such as thinking that they can create a webpage only with CSS, but you can't. I guess the best way to think of CSS is that it is a 'modification' of HTML, which can be inserted into already-created HTML pages to completely change the layout. A good example of how CSS styles are used is the CSS Zen Garden. This site uses the same HTML in all versions of it, but the CSS file location is changed. See the CSS Zen Garden for yourself, if you want, and have a little play around with the different CSS files, and look at the effects. Also note that this site doesn't use tables (HTML tag: <table>), but CSS divisions and spans (HTML tags: <div> and <span> respectively) instead. There are two basic ways to insert CSS into an HTML page (there is also another one, which I will explain later). The first way is to insert it directly into the page, within the header (HTML tag: <head>): HTML Code: <style type="text/css"> <!-- CSS goes here. --> </style> HTML Code: <style type="text/css" src="http://www.yoursite.com/directory/cssfile.css" /> Now that you know a little about what CSS is and what it does, lets move on to some actual coding... 2. CSS Syntax The syntax for CSS is relatively simple and universal (although certain browsers do not support some CSS attributes or elements). The most basic CSS style would look like this: Code: element {attribute: value;}
To specify multiple attributes for a single element, rather than repeating the above code many times, you can do this: Code: element {
attribute1: value1;
attribute2: value2 value2a value2b;
attribute3: value3;
}
3. Basic CSS Now, let's get ready for some actual CSS examples... Example 1 For our first example, we want to modify all text within a paragraph (HTML tag: <p>). To do this, we make the element "p", which means that we want to apply the following CSS attributes to every paragraph in the HTML, and we want to set the colour of the text in these to red. This is how we would do it: Code: p {
color: red;
}
Example 2 Next, we will just evaluate on this a bit more, by adding more attributes. We will want our paragraphs to have:
Code: p {
color: #FF0000;
text-align: center;
border: 3px outset #00FFFF;
background-color: white;
padding: 5px;
margin-left: 15px;
}
Code: p {
color: #FF0000;
text-align: center;
border-width: 3px
border-style: outset;
border-color: #00FFFF;
background-color: white;
padding: 5px;
margin-left: 15px;
}
Continued to next post (too long)... |
| | |
| | #2 (permalink) |
| Newbie | Continued from previous post... 4. The Element Extended You can specify more than just HTML tags as the element. You can make it so it only applies to certain classes; IDs; classes, IDs or tags within others; or basic behaviours. Below are some examples with explanations of some possible ways of defining the element: Code: body {}
Code: .classname {}
HTML Code: <table class="classname"> Code: #thisid {}
HTML Code: <td id="thisid"> HTML Code: <body style="color: red, background-color: blue"> Code: h1, .class, #id {}
Code: a:hover {color: green}
Now let's make a small CSS script which is used for the class 'menulink'. For this, we want the normal text to be hex colour #FF0000 and underlined, but we also want to make it change colour for different things. When it is hovered over, we want it #00FF00, with a background colour of white; when it is a visited link, we want it #00FFFF; and when it is an active link we want it #000000. Here iss the CSS for what we need to do this: Code: .menulink {
color: #FF0000;
text-decoration: underline;
}
.menulink:hover {
color: #00FF00;
background-color: white;
}
.menulink:visited {color: #00FFFF;}
.menulink:active {color: #000000}
HTML Code: <h1 class="menulink"> 5. <div> and <span> Without CSS, these two HTML tags do virtually nothing at all (except <div> may act similar to <p> around text). But with CSS, they can be two of the most important tags in terms of layout/decoration. How they act with CSS is fairly simple to explain: you can use them the same way you use any other tag with CSS, such as defining the tag itself in CSS, or naming the tag with an ID and/or class attribute. For example, the CSS: Code: #div1 {background-color: black;}
HTML Code: <div id="div1">Div contents here...</div> 6. Conclusion We can now see the various ways CSS can be used to customize web pages, that are much more efficient and effective than plain HTML pages. And as all the CSS within a page can be defined in the header of an HTML document, near the top, it lets you easily edit the entire layout and decoration of a page in some script which is all grouped together, and even within a separate file if you wish. You can now (if you haven't already) implement CSS into your own site, and see and make good use of the many advantages it has. If you wish to delve a little deeper into the world of CSS, I would recommend these following sites for learning and reference:
If you have any questions, suggestions, corrections, or anything else, please reply feedback to this thread so I can answer/reply/fix it. Thank you. No part of the above tutorial was taken from any other author's work, 100% of it was completed by me. I hope it may have helped you on your way to CSS transcendence in some way. ? Copyright 2005 Adam Freeth (Zaltan or Zalt4n). No part may be reproduced without prior permission of the author. (To prevent plagiarism.) |
| | |
| | #3 (permalink) |
| WMT Addict | Wow! That's a very long post! Haha, i couldn't read it all, but i got through a large chunk of it, and this looks like pretty good stuff! Great job, i'm giving you some reputation for this
__________________ Kingdoms Of Battle << Check out my free to play online strategy game! SomeCoders - Coding blog, coding tips |
| | |
| | #4 (permalink) |
| Newbie | Oh, I just realised there is a Tutorials section, which would probably better suit this 'tutorial'... Oh well. If there's much interest in this, I'll post another tutorial on CSS which will extend more into using <div> to create professional-looking 'blocks', such as menus or anyone other content which could be displayed that way, and some other things. So... any interest? |
| | |
| | #5 (permalink) |
| Moderator | That is quite a good tutorial for beginners, but i will stick with frontpage to make my CSS.
__________________ Free .org domain - Click for details! Do not pm asking for things. My inbox is full. Add me to MSN! |
| | |
| | #6 (permalink) |
| Newbie | But the problem with web design programs is that they have limited use. I use Dreamweaver MX, which has high CSS capabilities, but I still write the CSS is plain code. It's one of the easiest languages to learn, as long as you already know HTML (so people who use a design program for everything are very limited). When I get the time to create to follow-up tutorial, it will go into CSS which would be impossible to do in a web design program -- yet the CSS with do extremely powerful things with not much of it. |
| | |
| Tags |
| beginners, css, tutorial |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Free SEO Guide for Beginners | manika | Search Engine Optimisation (SEO) | 4 | 31-10-2008 11:35 |
| A beginner AJAX tutorial | LiberMan | Programming / Scripting / Coding | 1 | 04-09-2008 01:34 |
| Html Tutorial Part Three*frames | Morphmaster | Programming Articles | 1 | 14-05-2005 21:56 |
| Html Tutorial Part Five *Forms | Morphmaster | Programming Articles | 0 | 14-05-2005 21:54 |
| The graphic tutorial and tip sites thread | Zing! | Graphics Forum | 4 | 10-04-2005 15:24 |