Jul 27, 2008

Defining Colors Using Css

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > CSS (Cascading Style Sheets)

free web hosting

Defining Colors Using Css

delivi
We can specify the colors using different techniques in CSS to use within documents. No color should ever be specified within an XHTML document, it should be specified through CSS.

Lets see the different ways of specifying colors.

I. Using Color Names

You can use color names for specifying a standard set of colors. Only 16 named colors are valid for CSS. They are,
White (#ffffff), Black (#000000), Red (#ff0000), Green (#008000),
Blue (#0000ff), Silver (#c0c0c0), Gray (#808080), Teal (#008080),
Lime (#00ff00), Olive (#808000), Yellow (#ffff00), Maroon (#800000),
Purple (#800080), Fuchsia (#ff00ff), Navy (#000080), Aqua (#00ffff)

II. Using RGB Hex Codes

RGB Hex codes are most commonly used to specify colors in CSS. RGB Hex codes are six digit hexadecimal numbers. A hexadecimal numbers is made up of the digit 0-9 and letters A-F, where A representing 10 as a single digit, through to F representing 15).

Each RGB Hex Color code contains of three parts. Each part when converted to decimal will be equal to a value between 0 and 255 (00 to FF).

An example RGB Hex Color code is "#FFF8DC". The first pair of digits refers to the amount of red in a color ("ff"), the second specifies the amount of green ("f8"), and the last pair the amount of blue ("dc").

The RGB Hex Color code is always prefixed with a # symbol.

III. Using Short RGB Codes

When each of the three pairs of a RGB Hex color code consist of two of the same digit, for example #ffdd77, the code can be shortened or abbrevated as #fd7.

Remember this can only be done only when all three of the pairs are made up of two identical digits.

IV. Using Decimal Values

CSS allows you to specify the color values in decimal form. This will be quite useful if you have trouble working with hexadecimal values. You can just get the decimal values for the colors you use from your image editor or a color picker.

The following syntax is used for decimal color definitions in CSS:
CODE
* {
    1. color: rgb(255, 248, 220);
}


The above code translates to the color #fff8dc. The value for each of the three colors red, green and blue - is defined as a number between 0 and 255.

IV. Using Percentages in RGB

The Colors can also be specified in CSS as percentages in RGB. You need to add the percent sign (%) after the number you wish to use as percentage for each color.

The following syntax is used for defining colors using percentages in RGB:
CODE
*{
      color: rgb(100%, 60%, 200%);
}


The value for percentage ranges from 0 to 100 for each color component.

Note:
* If the value used for specifying colors exceeds the limit i.e. greater than 255 then the maximum value is used.
* No negative values will be accepted.
* Only the Hex Values for colors is supported by all other web programming languages.

 

 

 


Reply

jlhaslip
And here is a page with lots of colour choices to assist with Hex colour-codes:

http://jlhaslip.trap17.com/samples/colour/colour_grid.html

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:

Recent Queries:-
  1. css rgb number code - 162.17 hr back. (1)
Similar Topics

Keywords : defining colors css

  1. Css Problem - I cant get the right colors. (4)



Looking for defining, colors, css

Searching Video's for defining, colors, css
advertisement



Defining Colors Using Css



 

 

 

 

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