Jul 27, 2008

A Guide To Css And Creating A Stylesheet

Free Web Hosting, No Ads > CONTRIBUTE > Tutorials
Pages: 1, 2

free web hosting

A Guide To Css And Creating A Stylesheet

beeseven
Table of Contents:
I. Introduction
II. Starting your stylesheet
--A. Starting syntax with font-family
--B. Defining classes
--C. Using classes
III. The STYLE tag
IV. Comments in CSS
V. The "a" tag
VI. A quick list of common attributes
VII. Notes
--A. Universal classes
--B. Grouping
--C. Multiple instances
VIII. Finding other attributes
IX. Closing

I. Introduction
Firstly, to begin using a stylesheet, you must have one. Open up your text editor and save as (something).css. I know NotePad doesn't need quotes for a stylesheet, but I'm not sure about other programs.

Now what good is a stylesheet if you don't know how to use it? to include a CSS document in an HTML page, simply put this in the head:
CODE
<link rel="stylesheet" type="text/css" href="(location)">
Where (location) is, you guessed it, the location of the file. If it's in the very top directory you can use "/stylesheet.css" or you can make it relative like "../stylesheet.css" or whatever (for those who don't know "." is current directory and ".." is up one level).

II. Starting your stylesheet

II. A. Starting syntax with font-family
Now for the actual CSS:
To change the style that something appears in, you put the tag followed by a bracket, then the styles, then a closing bracket. For example, you specify a font with the font-family attribute, and if you wanted your entire page in Wingdings (and who wouldn't?) you could put:
CODE
html {
       font-family: Wingdings;
}
Now, you don't have to have it spaced like that, it'll still work fine if you don't, but it's sort of the convention. You always end an attribute with a semicolon. But suppose not everyone that visits your site has Wingdings installed on their computer. Since it's the font family, you can specify multiple fonts in order of preference, separated with commas:
CODE
html {
       font-family: Wingdings, Webdings, Symbol, Times New Roman, Sans-Serif;
}
I added Sans-Serif in there because the W3C likes it when you end with a really really general family. There are a lot of different attributes that deal with font, but I'll get to those later.

II. B. Defining classes
You can change attributes for pretty much any tag, p, i, h1-6, div, td, form, hr, just to name a few. You can't make your own tags, though. But what happens if you run out of tags? You can assign classes to most tags, but if you're not basing the attributes on anything, P or DIV is best. To assign a class, you just put the tag followed by a period followed by the class.
CODE
div.error {
       font-style: italic;
       color: rgb(255,0,0);
       font-size: 8pt;
       font-family: Arial, Verdana, Sans-Serif;
}
Here I've stated that when I use a div tag with the class "error," the text will be Arial, red, italic, and 12 pt. Color is font color, and you can also use hex values with it.

II. C. Using classes
So how do you use this? When you want to display an error, just put this:
CODE
<div class="error">An error has occured (or your text)</div>
It will appear like this:
An error has occured (or your text)
(or as close as I can get, having only the numbers 1-7 at my disposal for size). Your class can be any name you want. Also, if you base it off another tag, like <h2 class="announcement">, then it will have all the properties of h2 and also the ones you specify. You also probably shouldn't change properties of a tag drastically that will appear a lot (I once made "i" red for errors, then turned some text red with i inadvertantly).

III. The STYLE tag
Now if you don't want something to appear in the stylesheet but you need it for one page, you can put this in the head:
CODE
<STYLE type="text/css">
html {
       font-family: Wingdings, Sans-Serif;
}
</STYLE>
You can do all the same things in the STYLE tag that you can in a stylesheet.

IV. Comments in CSS
Comments, like in programming and HTML, are stuff that is ignored when the thing is actually run. I only know of one way to comment in CSS that won't make the W3C validator mad at you, and that's /* and */. You can place one line or multiple line comments between /* and */. I thought that you had to start each non /* or */ line with a *, but after another W3C validator check it seems not to be the case.

V. The "a" tag
The a tag has a few different things you can do with it, because it has different states. There's normal, hover, visited, and active. To change the attributes of normal you just do "a," for hover you do "a:hover," visited is "a:visited," and active is "a:active." You can change the attributes of each independently of one another. Say, for example, you want a link to be blue and have no underline, but on hover you want it to turn yellow, have an underline, and be bold. Then you want a visited link to look like the normal but be grey, you could do this:
CODE
a {
       text-decoration: none;
       color: blue;
}
a:hover {
       text-decoration: underline;
       color: rgb(255,255,0);
       font-weight: bold;
}
a:visited {
       text-decoration: none;
       color: #C6C6C6;
}


VI. A quick list of common attributes
Some attributes you might need:

font-family - set fonts in order of preference
font-weight - normal, bold, or a number 100-900 (normal is 400 and bold is 700)
font-style - normal, italic, oblique (don't know what oblique is)
text-decoration - none, underline, overline, line-through, blink
text-transform - none, uppercase, lowercase, capitalize
text-align - left, center, right, justify
color - font color in rgb ("rgb(x,y,z)"), hex ("#UVWXYZ") or color name
text-indent - sets indent in pixels (px) or % of page
line-height - "normal," relative to font (#em), length, or % of font size (double spacing would be "2em"
background-color - sets background color in rgb, hex, or color name
background-image: usually defined under BODY, usage is " url("YOURURLHERE") "
width - auto (browser calculates), % of page, or length (px, cm etc.)

But that's just a few simple ones, there are many more.

VII. Notes

VII. A. Universal classes
If you want to have a few common things between tags, you may omit the tag for a class, and only put the tag name. For example, if you want to have several things centered but do not want to make a new class for each, you can just put this:
CODE
.center {
       text-align: center;
}
Since you didn't specify a tag, you can now use class="center" on any tag and it will be centered.

VII. B. Grouping
If you don't want to type the same attributes over and over again for multiple tags or classes, you can group them together. Let's say you want all your headings to be centered, no matter what. You could make a class for each or make a universal class to save some typing, but you could save even more by grouping them together:
CODE
h1, h2, h3, h4, h5, h6 {
       text-align: center;
}
That way, you don't have to type class="center" for every one.

VII. C. Multiple instances
If you want to make it so that something doesn't happen the first time but happens every other time, you could use, for example, "p+p." If you were going to write a long essay or something, you don't have to indent the first paragraph because of some weird convention, so you could do this:
CODE
p+p {
       text-indent: 20px;
}
This makes it so every "p" tag with a "p" tag right before it is indented. The first paragraph won't be, because there isn't a "p" proceding it.

VIII. Finding other attributes
I have almost certainly not covered all the attributes that you will use with CSS. When I need to find a new one or look up how to use it correctly, all I do is go to Google and type "CSS (attribute I need to find) site:w3schools.com" (without the quotes). This returns everything containing the attribute I need from the w3schools CSS tutorial. W3schools has really good documentation of the attributes and how to use them.

IX. Closing
So why use CSS? Because the w3c tells us to, of course! But seriously, it will work better in most browsers and it is a LOT more customizable than just HTML. Sometimes I actually do my homework in CSS, because it doesn't try to autoformat all my stuff like Word does. I hope that this tutorial helped whoever read this far, and I'll answer any questions about it that I can.

 

 

 


Reply

Joshthegreat
Nice tutorial there. If i didn't know CSS already I would have found that very helpful. That's some good work right there.

Reply

fsastraps
Very helpfull tutorial, too bad i just learned all that tool. lol But i bet is definately going to help a lot of people

Reply

HmmZ
Very nice tutorial,
Easy to follow,
Good to apply, you motivated me smile.gif


Just a question, i used a stylesheet, in that stylesheet I included some "absolute" positions for my website tables (main menu, stats, shoutbox, etc..) and it shows fine in Firefox, but in IE it looks like crap, the tables are overlapping each other (main menu and stats) so what do i need to do?smile.gif

Reply

beeseven
Short answer: don't use IE
I guess you could try to replicate the absolute lengths with percentages, but absolute lengths are weird and don't go across different browsers well.

Reply

HmmZ
I think it would be hard editing them with percentages instead of px positoning, what about relative positioning instead of absolute? (wait, relative=%? unsure.gif )

anywayz...I seem to have fixed, it's showing correctly now smile.gif, but the question stays whats best to use, it seems absolute positioning works good enough?

Reply

doom145

Huge un-needed quote deleted


thanks....this is very "interesting" lol.....CSS isnt used very much these days exept for like basic websites.....But i still like css as u have the right to choose which colour and so forth......the only problem about it is that it can only do a certain thing.....u cant go beyond that point which is anoying because if css has more syntax involved then it would be better and you could make it look more professional and make a site that people would like....but overall i gave this tutorial a 9/10

Reply

beeseven
Really? I'd think it's used a lot more than it used to be. It also helps with browsers that don't know HTML *coughIEcough* You can do a lot more than I put there, there's a huge number of attributes.

Reply

Hamtaro
Actually, from what I've seen, CSS is used with MOST professional sites. I can't really recall a site that I've ever been to (Except my site when I first started it) that doesn't have CSS in it.
I'm still learning new CSS stuff. I've been doing CSS (At least half-way decently) for a little over a year now, and I continue to find new things.
I prefer percentage positioning to pixel positioning. That way, the layout of the site can be relatively the same in each browser. (My site's positioning works the same in Firefox and IE.)
Oh, this may be a little late, but nice tutorial. I learned some things in it that I didn't know about CSS.

Reply

nickmealey
CSS is very well used today. I use it all the time

Reply

Latest Entries

sportytalk
yep, is a very nice tutorial. I know it's over a year old, but I've only just come across it after it was bumped.

I did know a bit about CSS, but it isn't my strongest language / part of website development. After reading this tutorial, it has basically reminded me of everything relating to CSS and pretty much confirmed what I thought I knew.

If I ever need help on CSS, which I probably want, (i have needed help a couple of times before though) I can now come into this topic on this forum and reread. The topic looks easy to follow and looks fairly easy to understand.

Thanks for sharing, even If I don't really have a use for CSS and don't need to keep referring back to tutorials or user guides, i'm sure there's other users on the site that will need the guide, or have needed to use it since the topic has been online smile.gif

Reply

Teragonto
Very nice tutorial beeseven. I liked how you thoroughly explained it since the CSS tutorials one WCSchools makes my head hurt with all the formatting. This one has hardly any format.

Reply

moonwitch
CSS can be a huge help for the bigger projects to have a uniform look. Also it keep "looks" and content more seperated. As far as the need for a "test" page with all categories on it to test the css... I just keep my CSS file open (I always use external css files smile.gif) and add to it as I go along. To keep a style sheet from getting cluttered I prefer to keep the main tags on top and then classes. I also am a big fan of comments in my pages (be it HTML, be it CSS) this will make it easier when you do decide to work on a site in team.

The biggest disadvantage in CSS (to me personally) is that IE doesn't support all CSS (even though M$ insists that IE does support CSS2). For example a hover effect in CSS with nested lists, which creates awesome looking menus, will NOT display as such in IE. The best example of this can be found on Eric Meyer's Web

The nested lists menu can be found here, I suggest looking at it with IE and Netscape/Mozilla/FireFox (Konqueror should support this too, I believe Opera does as well, but I am not sure)

Reply

mzwebfreak
One of the best things I've found for working with css stylesheets is that you need to have a page, i.e. test.html, where you have the different categories all listed on this one page so you can check by trial and error to make sure all the styles work together with the layout correctly. And, if you're viewing it in ie or firefox, you can just edit the color scheme as needed, save the css file, and then F5 the page to make sure everything still works together.

Reply

maddog39
Great tutorial. I am going to use this very much. I also posts the link in a tutorials mod on this websites forums. biggrin.gif

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Pages: 1, 2
Recent Queries:-
  1. sample css class=error stylesheet - 54.23 hr back. (1)
Similar Topics

Keywords : css creating stylesheet

  1. Getting Started With Mysql - creating tables and insert data into them. (2)
  2. Delete Files And Directories Using Php - following up from creating and writing (7)
    How To Delete Files and Directories follow up from creating them Hello all and
    welcome to my second tutorial involving file management. In my previous tutorial , I explained how
    to create, write and read files. In this tutorial I'll explain how to remove the files and
    directories you took so long to create. I did not explain last time how to create directories as I
    did not know, now I do, you can use the mkdir() function. Now with this tutorial.... Removing
    Files Removing files can easily be done with the unlink() function: CODE <? un...
  3. Simple Stylesheet Tutorial - Stylesheet embedded in your site. (2)
    Hi - ill show you how to make a simple style sheet that will be embedded into your site. OK make
    sure your site is set up already (like the standard tags) To start and end off a stylesheet you
    need to do the following CODE <style type="text/css"> </stlye> Ok
    lets start CODE <style type="text/css"> p { font-family: "Tahoma";
    font-size: 9; color: "red"; } </style> So when you come to put in
    CODE <p>Hi!</p> The text will appear red and will be in Tahom...
  4. Creating A Timer Program - Using Visual Basic 2005 (8)
    This tutorial will explain how to create a basic timer using Visual Basic Express 2005. If you
    don't have it, it's free and you can dowload it from Microsoft's website. All you need
    is a few minutes to sit down and read this and a version of Visual Basic. OK, so what will this
    timer actually do? Well, you are able to enter a number of minutes and a message, and then click a
    button. Once the timer is up, your message pops up and you are reminded! So, basically it's
    a little reminder system. I use it to remind me when TV programmes start, when I have to...
  5. Creating Navigation For Html Websites - Have a common navigation menu for the whole website! (12)
    Pre-requisite: HTML, inline frame tags 1 Attachment(.zip) included. Updates : 29-12-07: Doctype
    added in example files (Advised by jlhaslip) Designing a whole website takes a lot of planning
    and organization. Designing a proper navigation system is a basic step in building your website. If
    you are developing webpages in html you would have observed that as you go on creating pages it
    becomes difficult to maintain the links to the pages. This article will guide you in developing a
    common navigation menu for your website. It describes three ways, so if you don'...
  6. Creating A Resume - 10 Tips For Making A Resume (1)
    I've been working on my Resume for months now. Here is a summary of what I've learned: 1.
    Avoid referring to yourself via 1st person or 3rd person terms. Rather than saying "I started this
    job in" just say "Began job in"... Employers expect Resumes to be professional and avoid reference
    to oneself; and instead speaking in an impersonal tone that presents
    achievements/skills/experience/education without personalization. Avoid words like "I", "my", "he",
    "she", etc. Leave out personal pronouns and only use the action words/verbs. This also includes
    your Ob...
  7. Programming In Glut (lesson 4) - Creating 3D objects (0)
    Lesson 4 of 6. I hope you are enjoying them /laugh.gif" style="vertical-align:middle"
    emoid=":lol:" border="0" alt="laugh.gif" /> . QUOTE Hello, in this tutorial we will be creating
    a 3D pyramid. We are building this tutorial from Lesson 3, but I took out the 2D objects and placed
    a 3D pyramid in there instead. The 3rd axis for drawing can be a litle confusing, but after you get
    the hand of it you'll do fine. Now when you are setting a 3D vertex just remember that the
    camera is on the positive end of the z axis. So things that have a more positive z axis va...
  8. Programming In Glut (lesson 1) - Creating a windwo (0)
    This is the first of six lessons I am transferring from Astahost for programming in GLUT, and after
    the six I hope to make more, I hope you enjoy. QUOTE Hello, I'm starting a series on how to
    program in OpenGL using the OpenGL Utility Toolkit, a.k.a. GLUT. I chose GLUT because it is quick
    and easy to write, and very easy to learn. In this tutorial I am going to teach you how to create a
    basic window which we will build off of in later tutorials. Throughout the tutorial I will leave
    notes to let you know what each command does, and how you can modify it to fit...
  9. Creating Your Own Icon - (23)
    It is easy to create your own icon, just pick a bitmap (.bmp) file and change its extension to .ico.
    To do so, open the Windows Explorer, click on the View menu (or Tools in WinMe), click Folder
    Options, click View tab, remove the check on the "Hide file extensions for known files types"
    option, and then click OK. Select a bitmap file, press F2 key, and then change its extension to
    .ico. Have fun learning:)...
  10. Tutorial: Creating Custom Icons For Devices - Give that device a great icon every time you plug it in! (0)
    Ok for this tutorial I will use the PSP as an example of the device, this should work for every
    device. (THIS WILL NOT HARM ANYTHING AT ALL!) First off, open notepad and type in:
    ICON=ICONE.ICO Save that as AUTORUN.inf Now, find a picture you like.. make sure its dimensions
    are 16X16 pixels. Put it in the main folder of the device, for example, my psp is located at
    F:\, i would type in F:\ to the adress bar and put the picture in that folder, as it is
    the folder your computer automatically reads, anyways, put your picture in there and name it: ICO...
  11. Creating A Simple Image Viewer - Using Visual Basic 2005 Express Edition (3)
    I downloaded Microsoft's Visual Studio Express suite a few months ago, but only recently got
    around to installing it. I have been practising with Visual Basic and making some rather basic
    programs and utilities, but they contain most of the basic concepts. This tutorial will explain how
    to create a basic image viewer, and I will try to explain each step from beginning to end as clear
    as I can. To start you will need: Microsoft Visual Studio About 10-20 minutes free time OK,
    first open up the Visual Basic part of the Studio. I am using the 2005 Express version, so...
  12. Getting Started With Amfphp And Rias - first steps in creating RIAs (0)
    AMFPHP in a short way is a library of php files that let u manage in JUST ONE FILE what u would do
    in many files like for example queries to mysql. So u can have tons of queries to mysql and all of
    them in just ONE FILE! so what is a RIA? a RIA is a Rich Internet Application commonly given
    to flash applications, not the animations or presentations we see daily on the internet but very
    useful and cool programs made in flash. the fisrt step u need to take is to download the AMFPHP
    library directly from its site at www.amfphp.org, in some free hosted sites the latest...
  13. Creating Rollovers With Buttons - Short & simple javascript tutorial that shows you how. (2)
    Javascript in action can render some very neat visual effects, which can make your website more
    appealing, and sometimes even easier to navigate. Among the most common effects are the
    'button' effect, and the mouseover effect. The buttons are very common, of course; if
    nowhere else, most of us have seen them at the end of forms (Click the 'submit' button to
    proceed...). The basic idea is to have a 'depressible' object, which can give you the
    illusion that you're 'pressing' it when you click it. The rollover effect causes
    something to h...
  14. Creating Personal Alarm - To remind you something (2)
    Creating Personal Alarm This personal alarm is very useful to remind you something or anything you
    would like it to do. Use Task Scheduler application to create your personal alarm. First, click on
    Start -> Settings -> Control Panel -> Scheduled Tasks. Now click on the Add Scheduled Task wizard
    in the Task Scheduler folder. Click Next, click the Browse button, and then select your favorite
    sound files (WAV/MP3/MIDI). Set the file to open as the task daily. Set it at the top of the hour
    every day, open up its advanced properties. On the Schedule tab press the Advance...
  15. Creating Your Own Php News System - (23)
    Hello, heres a simple tutorial from a script that I made to power my news system. It is written
    withthe PHP coding system and consists of 8 files using a flatfile based system, without MySQL
    databases. This should be usefull for those who want a simple little news manager and like to have
    simplcity without the fancy date strings and sutff. You can see a demo of it at my site @
    http://www.xeek.trap17.com . Let's Start! First let's start with the easy stuff,
    making the directory first, first create a main directory to hold everything, call this folder "ne...



Looking for guide, css, creating, stylesheet

Searching Video's for guide, css, creating, stylesheet
advertisement



A Guide To Css And Creating A Stylesheet



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE