Saturday, January 11, 2014

CSS Part 3

CSS Rules Overriding: 

We have discussed four ways to include style sheet rules in a an HTML document. Here is the rule to override any Style Sheet Rule.


  • Any inline style sheet takes highest priority. So it will override any rule defined in <style>...</style> tags or rules defined in any external style sheet file. 
  •  Any rule defined in <style>...</style> tags will override rules defined in any external style sheet file. 
  •  Any rule defined in external style sheet file takes lowest priority and rules defined in this file will be applied only when above two rules are not applicable.

Handling old Browsers: 

There are still many old browsers who do not support CSS. So we should take care while writing our Embedded CSS in an HTML document. The following snippet shows how you can use comment tags to hide CSS from older browsers: 

<style type="text/css"> 
<!-- 
body, td {    
   color: blue; 
--> 
</style>

CSS Comments: 

Many times you may need to put additional comments in your style sheet blocks. So it is very easy to comment any part in style sheet. You simple put your comments inside /*.....this is a comment in style sheet.....*/. 
You can use /* ....*/ to comment multi-line blocks in similar way you do in C and C++ programming languages. 

Example: 


/* This is an external style sheet file */ 
h1, h2, h3 { 
color: #36C; 
font-weight: normal; 
letter-spacing: .4em; 
margin-bottom: 1em; 
text-transform: lowercase; 
/* end of style rules. */

CSS - Measurement Units 

Before we start actual exercise, I would like to give a brief idea about the CSS Measurement Units. 
CSS supports a number of measurements including absolute units such as inches, centimeters, points, and so on, as well as relative measures such as percentages and em units. You need these values while specifying various measurements in your Style rules e.g border="1px solid red".  
We have listed out all the CSS Measurement Units alogwith proper Examples:


CSS – Colors 

CSS uses color values to specify a color. Typically, these are used to set a color either for the foreground of an element(i.e., its text) or else for the background of the element. They can also be used to affect the color of borders and other decorative effects. 
You can specify your color values in various formats. Following table tells you all possible formats:

These formats are explained in more detail in the following sections: 

CSS Colors - Hex Codes:

A hexadecimal is a 6 digit representation of a color. The first two digits(RR) represent a red value, the next two are a green value(GG), and the last are the blue value(BB). 
A hexadecimal value can be taken from any graphics software like Adobe Photoshop, Jasc Paintshop Pro or even using Advanced Paint Brush. 
Each hexadecimal code will be preceded by a pound or hash sign #. Following are the examples to use Hexadecimal notation.


CSS Colors - RGB Values: 

This color value is specified using the rgb( ) property. This property takes three values, one each for red, green, and blue. The value can be an integer between 0 and 255 or a percentage. 
NOTE: All the browsers does not support rgb() property of color so it is recommended not to use it. 
Following is the example to show few colors using RGB values.


Browser Safe Colors: 

Here is the list of 216 colors which are supposed to be most safe and computer independent colors. These colors very from hexa code 000000 to FFFFFF. These color are safe to use because they ensure that all computers would display the colors correctly when running a 256 color palette:




No comments:

Post a Comment