Computers and Technology
CSS intro
Okay, I know this topic is nothing new and you’ve read hundreds of tutorials about it, but for a newbie like me, it’s still fascinating.
CSS = cascading style sheets. Basically, CSS is a compilation of styles and formatting elements you can add to your HTML code such as different fonts, colors, and other. It has replaced older, more traditional tags such as <font> and <align>. The best way to use CSS is to create a separate .css file that you’ll link into your HTML code like this:
<link rel=”stylesheet” type=”text/css” href=”filename.css”>
Add that into your <head> tag and the whole html file will follow these rules. This basically tells the browser that there is a stylesheet CSS in text that can be found under the name “filename.css”. You can also create in-document styles using this tag in the <head>:
<style type=”text/css”>
After you place this tag into the document, just write your style definitions and end the tag with </style>. Here is an example of that:
<head>
<style type=”text/css”>
p {color: blue; margin-left: 5 px}
</style>
</head>
I just created a style in which every “<p>” or paragraph in the HTML document will be in blue with a five pixels margin from the left. You can use this same technique for a specific paragraph, using the <style> tag, if you wish to like this:
<p style=”color: blue; margin-left: 5px”>
Text
</p>
There are a few commonly used tags associated with CSS:
- <style>- this tag gives you the straight style definition, there’s nothing more to it. You can use several different attributes with this tag.
- <div> - creates a division in the document. You can create a “block” in the HTML code using div. It’s usually used for formatting the layout of a page.
- <span>- similar to div, span is meant for smaller portions of HTML to define. Usually used with “class” and “id” attributes
- <link>-is pretty self-explanatory and used in an example at the beginning of this article
How to write CSS:
CSS has a distinct form:
.newstyle{
property: value;
}
You can define a class this way and use it like this:
.fontstyle{
font-weight: bold;
}
<p class=”fontstyle”> style text </p>
The text would show up bold. You can put multiple properties under one style but they always have to be separated by “;” (just like in PHP). Now, let’s say you want all of the paragraphs to be bold, there is no sense in applying “class” to each one of them so you can apply the value a tag:
p {font-weight: bold;}
Now all paragraphs will show up in bold. You can redefine basically any tag this way in CSS. It’s a very powerful tool. You can define multiple tags at once as well:
h1, h2, p
{
color: green;
}
The same way, you can use multiple classes on a tag:
<p class=”mystyle mystyle2 boldstyle”>Text </p>
In this example, the paragraph will be formatted according to three separate classes. The possibilities are endless with CSS. Let’s look at “id”‘s :
#myid { color: green}
p#pid { text-align: left}
The first is just a regular ‘id’ that you can apply to basically almost any tag. The second definition can only be used with paragraphs or the <p> tag.
One last thing that you should probably know about CSS, how to make comments. This is similar to PHP:
/* comment goes here */
And that’s it. In my next tutorial, I’ll show you how to do a basic format of your page using CSS. See you next time!
| Print article | This entry was posted by Admin on September 19, 2009 at 16:35, and is filed under HTML/CSS, Tutorials. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |



about 2 years ago
Thanks for the tutorial, i advice beginner to read it
about 2 years ago
Nice tutorial. Perfect for the noobs out there
about 2 years ago
thanks
haha, it’s cause I’m a noob at it myself
about 2 years ago
ATrsHD I want to say – thank you for this!
about 2 years ago
all good things
about 2 years ago
needed here
about 2 years ago
lot about you
about 2 years ago
site best
about 2 years ago
lP4Mg2 I want to say – thank you for this!
about 2 years ago
X3sgFb I bookmarked this link. Thank you for good job!
about 2 years ago
thank you very much
about 2 years ago
I want to say – thank you for this!,
about 2 years ago
no problem
check my other tutorials too.
about 2 years ago
Hello Establish klooper in F7*&%^! home of my english jer, buti danged charming re claim .
about 2 years ago
Great post.Thanks for sharing useful info. coupons
are great way to save money online. Check out coupons from all stores at deals365.us before you shop online.