PDA

View Full Version : Simple guide to CSS



Rifat
Apr 12th, 2006, 12:25 AM
This is tutorial/guide mainly for people who have minimal experience with CSS (Cascading Style Sheets) and want to learn a bit out about it. CSS is a stylesheet language that formats the presentation of a document written in a markup language (e.g. HTML, XHTML, XML). CSS has a number of advantages one of the main ones being the presentation of websites can be held in one place, therefore making it really simple to update webpages. Style sheets make sites load faster and doesn't use require much bandwith. CSS specifications are maintained by W3C (World Wide Web Consortium).

Adding stylesheets within the HTML file:


<html>
<head>
<title></title>
<style type="text/css">
body {
color: white;
background-color: #000000;
}
</style>
</head>

<body>
[etc...]
</html>


Style sheets in CSS is made up of rules, and each of these rules has three parts to it.

- the Selector (example: 'body') : specifies which part of the document will be affected by the rule

- the Property (example: 'color' and 'background-color') : specifies what aspect of the layout is being set

- the Value (example: 'white' and '#000000'): gives the value for the property

Note: color values can be defined using hexadecimal notation to learn more about this go to this website - http://www.w3schools.com/html/html_colors.asp

Grouping selectors and rules:

Instead of having this:


body {color: white}
body {background-color: #000000}
We can have this:


body { color: white;
background-color: #000000 }

Just by using ';' to separate the properties.

OR

Instead of having this:


H1 { font-style: bold }
H2 { font-style: bold }
H3 { font-style: bold }

We can have this:

H1, H2, H3 { font-style: bold }

Will be adding more to this very soon.

Rifat
Apr 20th, 2006, 11:23 PM
Inserting a Style Sheet

There are a number of ways you can apply style sheets to a web page.

Inline styles:

To use inline styles you place a 'style' attribute in a HTML tag. The 'style' attribute can state any CSS information. Here is an example:


<p style=?color: blue; font-sizer: 12pt?>
What a nice sentence this is</p>

You can see how inside the 'style' attribute the style sheet language format is similar to the examples above. You still need a ';' to seprate the properties.

Internal Style Sheets:

Usually internal style sheets are placed in between the head tags in a HTML document. With the use of <style> tags CSS can be applied. An example on an internal style sheet:


<head>
<style type=?text/css?>
body {background-color: #900000;
text-family: arial;
text-size: 12pt}
</style>
</head>

Internal style sheets are usually used when the web master wants to give a certain look for a certain web page that differentiates from others in a web site.


External Style Sheets:

Probably the most popular way of applying style sheets, with external style sheets you create a separate document that contains all the CSS information. While in the HTML document <link> tags need to be placed so the browser can read the information from the style sheet document. The <link> tags need to placed in between the <head> tags.

Example:


<head>
<link rel= ?stylesheet? type=?text/css? href=?funkstyle.css? />
</head>

In the 'href' attribute you insert the name of your style sheet file and the browser will read the information in that file and format accordingly. Your style sheet file needs to be saved with the .css extension. The style sheet document doesn't need any <style> tags because it has already been saved as a CSS extension. A simple example of what a style sheet file can look like:



body {background-image: url(?image/discostu.jpg?);
font-family: arial;
font-size: 12pt}
p {color: blue;
font-family: aria}
h1 {font-size: 14pt}

freemovies
Apr 26th, 2006, 01:00 PM
thank you
the information you have provided is very helpful
it helped me in understanding some of the concepts
thanks

Rifat
May 3rd, 2006, 03:48 AM
Background Properties
In CSS background properties lets you set the background color for a web page and an image for the background. With the image background you are able to position the image, and also repeat the image horizontally or vertically.

Examples

Background Color:


body {background-color: blue} -> Color Name Value

body {background-color: #0000FF} -> Hexadecimal Values

body {background-color: rgb(0,0,255)} -> RGB Values
All of these properties do the same thing, they set the background color of the web page to blue. People have a choice of how they assign their value.

Note: A link to CSS Color Values ('http://www.w3schools.com/css/css_colorsfull.asp')

Background Image:


<style type="text/css">
body {background-image: url('waterbg.jpg')}
</style>
This basically assigns the image from the given URL, the URL is placed between brackets after the text 'url' as shown in the example.

Repeating a Background Image:


<style type="text/css">
body {background-image: url('waterbg.jpg');
background-repeat: repeat-x}
</style>
This background image is repeated horizontally, to repeat the image vertically simply replace repeat-x with repeat-y.


<style type="text/css">
body {background-image: url('waterbg.jpg');
background-repeat: repeat}
</style>
This repeats the image horizontally and also vertically.

Background Position:

The property for positioning images on backgrounds is; background-position. The values for background-position can be in the form of percentages (e.g. background-position: 100% 50%), length (e.g. background-position: 0px 30px), and keywords (e.g. background-position: right center). In all cases the horizontal position is specified first and the vertical position second. So for example the values 100% 0% will be positioned on the top right corner of the page.

Single Image on a Background:


<style type="text/css">
body { background-image: url('circle.gif');
background-repeat: no-repeat;
background-position: center; }
</style>
With this a single image, in this case a little circle would appear in the center of the page.

To have the image fixed at a certain point so it will not scroll with the rest of the page, just add this property to the body selector; background-attachment: fixed.

This link directs to a table that contains most background properties and values: CSS Background Properties Table ('http://www.w3schools.com/css/css_background.asp')

Rifat
May 3rd, 2006, 03:51 AM
thank you
the information you have provided is very helpful
it helped me in understanding some of the concepts
thanks
Great, glad I could help :)

Rifat
May 10th, 2006, 11:56 PM
Import Style Sheets

This is another way of applying a style sheets to a web page, very similar to external style sheets. You need to have a separate CSS file that contains all the the CSS information.


<style type="text/css" media="all">
@import url("mystyle.css");
p {background-color: blue;}
</style>

The @import has to be placed before all other rules.

JBelthoff
May 15th, 2006, 08:55 PM
Yes but you have to make sure that the browswers you are targeting support the import statement. Most modern broswers do but some older ones do not.

THis can also be used to your advantage when trying to do CSS Hacks of which there are plenty.

Enjoy!

;)

Rifat
May 19th, 2006, 01:04 AM
Ah yes I forgot to mention that, thanks JBelthoff. I think the import rule doesn't work for Netscape 4.x and IE 3.x. Internet Explorer 6 and browser below doesn't support the media property.

Charles_cz
Jun 4th, 2006, 11:03 AM
Here is tutorial (http://www.w3schools.com/css/css_intro.asp) I have found very useful. It is great for beginners.

urban
Jun 5th, 2006, 11:12 AM
thanks for the tut

webhostingrebates
Jun 14th, 2006, 12:10 PM
Very nice CSS guide. I have come to love developing my sites using CSS files. It makes it so much easy to tweak the look and feel.

Rifat
Jun 23rd, 2006, 01:37 AM
Very nice CSS guide. I have come to love developing my sites using CSS files. It makes it so much easy to tweak the look and feel.
We can all agree on that, and its so much more time efficient especially if you have a big website.

VirtuosoNetSolutions
Jun 29th, 2006, 04:07 PM
Here are valuable links for CSS as well

http://www.cleancss.com/
http://www.cssbasics.com/
http://cssmania.com/
http://www.cssplay.co.uk/menus/flyout_horizontal.html
http://cssvault.com/
http://people.opera.com/rijk/panels/css2.1-online/prop-visual.html

jackjazz
Jul 11th, 2006, 10:12 AM
;) Thanks for ur information.

princess275
Aug 28th, 2006, 12:33 PM
NIce work Rifat, keep it up

sonia
web design uk (http://www.xelonline.com)
web design manchester (http://www.webdesign-manchester.com)

antoniyo
Oct 30th, 2008, 05:01 AM
Go for w3school.com for Css. that is best place for guide any language.

owenwood123
Oct 6th, 2010, 02:10 PM
CSS background properties allows you set the background color for a web page as well as an image for the background. With the image background you are capable to lay the image, and also repetition the image horizontally or vertically.

Stone Cold
Oct 11th, 2010, 09:55 PM
I would like to comment on your fairtax idea though. I live in Arizona, which is a state that is overly dependent on sales taxes and has one of the lowest income taxes in the country. We have been hit particularly hard specifically because of the dependence on sales tax. Unemployed people don't pay any income tax and they don't spend a lot of money. But worse than that, even people who still have jobs don't have a positive outlook on the economy and they have stopped spending, hence a fiscal disaster.

davidharris789
Oct 18th, 2010, 08:29 AM
ahead yes I for instance to reference that, thanks JBelthoff. I think the import rule doesn't employment for neutral 4.x and IE 3.x. Internet Explorer 6 and bull's eye below doesn't confirm the media place.

aryans77
Oct 22nd, 2010, 07:03 AM
Thank You...This was quite information.....

samrose321
Nov 25th, 2010, 01:29 AM
generally internal style sheets are placed in among the head tags in a HTML document. With the apply of <style> tags CSS can be applied. An example on an internal style sheet:

rossking345
Nov 26th, 2010, 12:12 AM
In CSS background properties becomes you set the background color for a web page and an image for the background. With the image background you are capable to position the image, and too double the image horizontally or vertically.

lovelinebarbosa
Nov 26th, 2010, 11:56 PM
Make sure that you aim browswers support the import declaration. Most modern broswers but some are older. This can also be used to your advantage when you try to CSS Hacks that there are many.

jacksonmark97
Nov 30th, 2010, 02:29 PM
This is some other way of using a style sheets to a web page, real like to external style sheets. You require to have a separate CSS file that contains entirely the the CSS data.

markhill786
Dec 3rd, 2010, 01:06 PM
Internal style sheets are generally applied when the web master needs to devote a certain look for a certain web page that separates from others in a web site.

happydevas
Dec 9th, 2010, 04:54 AM
CSS background properties you can set the background color of a web page and the background image. When you insert the image background image, and even repeat the image horizontally or vertically.