Thursday, November 19, 2009

CSS Colors

 CSS has several options for defining colors of both text and background areas on your pages.

These options can entirely replace the color attributes in plain HTML. In addition, you get new options that you just didn't have in plain HTML.

For example, in plain HTML, when you wanted to create an area with a specific color you were forced to include a table. With CSS, you can define an area to have a specific color without that area being part of a table.

Or even more useful, in plain HTML when working with tables, you had to specify font attributes and colors etc. for each and every table cell. With CSS you can simply refer to a certain class in your tags.




Setting colors

Basically you have three color options with CSS:

1: Setting the foreground color for contents
2: Setting the background color for an area
3: Setting a background image to fill out an area

In the next section we will list the different properties that let you
do that.

In plain HTML, colors can either be entered by name (red, blue etc.) or by a hexadecimal color code (for example: #FF9900).

With CSS you have these options:




Common name
You can define colors with the use of common names, by simply enter the name of the desired color.

For example:


.myclass {color:red; background-color:blue;}

 Hexadecimal value
You can define colors with the use of hexadecimal values, similar to how it's done in plain HTML.

For example:


.myclass {color:#000000; background-color:#FFCC00;}

RGB value
You can define colors with the use of RGB values, by simply entering the values for amounts of Red, Green and Blue.

For example:

  
 .myclass {color:rgb(255,255,204); background-color:rgb(51,51,102);}

 You can also define RGB colors using percentage values for the amounts of Red, Green and Blue:

For example:



.myclass {color:rgb(100%,100%,81%); background-color:rgb(81%,18%,100%);}






 
  
   

No comments:

Css code

How it works:

A style is a definition of fonts, colors, etc.

Each style has a unique name: a selector.

The selectors and their styles are defined in one place.

In your HTML contents you simply refer to the selectors whenever you want to activate a certain style.

For example:

Instead of defining fonts and colors each time you start a new table cell, you can define a style and then, simply refer to that style in your table cells.

Compare the following examples of a simple table:

Classic HTML









this is line 1
this is line 2
this is line 3


With CSS (assuming that a selector called subtext is defined)





this is line 1
this is line 2
this is line 3


SELECTORS

Selectors are the names that you give to your different styles.

In the style definition you define how each selector should work (font, color etc.).

Then, in the body of your pages, you refer to these selectors to activate the styles.

For example:








This is normal bold

This is headline style bold




TAG SELECTORS


The general syntax for an HTML selector is:

HTMLSelector {Property:Value;}

For example:








This is a customized headline style bold




CLASS SELECTORS

The general syntax for a Class selector is:

.ClassSelector {Property:Value;}

For example:








class="headline"
>This is a bold tag carrying the headline class


class="headline">This is an italics tag carrying the headline class