Monday, March 17, 2014

CSS - Paddings

The padding property allows you to specify how much space should appear between the content of an element and its border:
There are following five CSS properties which can be used to control lists:
The value of this attribute should be either a length, a percentage, or the word inherit. If the value is inherit it will have the same padding as its parent element. If a percentage is used, the percentage is of the containing box.
You can also set different values for the padding on each side of the box using the following properties:
  • The padding-bottom Specifies the bottom padding of an element.
  • The padding-top Specifies the top padding of an element.
  • The padding-left Specifies the left padding of an element.
  • The padding-right Specifies the right padding of an element.
  • The padding Serves as shorthand for the preceding properties.
Now we will see how to use these properties with examples.

The padding-bottom Property:

The padding-bottom property sets the bottom padding (space) of an element. This can take a value in terms of length of %.
Here is the example:
<p style="padding-bottom: 15px; border:1px solid black;">
This is a paragraph with a specified bottom padding
</p>

<p style="padding-bottom: 5%; border:1px solid black;">
This is another paragraph with a specified bottom padding in percent
</p>

This will produce following result:
This is a paragraph with a specified bottom padding
This is another paragraph with a specified bottom padding in percent

The padding-top Property:

The padding-top property sets the top padding (space) of an element. This can take a value in terms of length of %.
Here is the example:
<p style="padding-top: 15px; border:1px solid black;">
This is a paragraph with a specified top padding
</p>

<p style="padding-top: 5%; border:1px solid black;">
This is another paragraph with a specified top padding in percent
</p>

This will produce following result:
This is a paragraph with a specified top padding
This is another paragraph with a specified top padding in percent

The padding-left Property:

The padding-left property sets the left padding (space) of an element. This can take a value in terms of length of %.
Here is the example:
<p style="padding-left: 15px; border:1px solid black;">
This is a paragraph with a specified left padding
</p>

<p style="padding-left: 15%; border:1px solid black;">
This is another paragraph with a specified left padding in percent
</p>

This will produce following result:
This is a paragraph with a specified left padding
This is another paragraph with a specified left padding in percent

The padding-right Property:

The padding-right property sets the right padding (space) of an element. This can take a value in terms of length of %.
Here is the example:
<p style="padding-right: 15px; border:1px solid black;">
This is a paragraph with a specified right padding
</p>

<p style="padding-right: 5%; border:1px solid black;">
This is another paragraph with a specified right padding in percent
</p>

This will produce following result:
This is a paragraph with a specified right padding
This is another paragraph with a specified right padding in percent

The padding Property:

The padding property sets the left, right, top and bottom padding (space) of an element. This can take a value in terms of length of %.
Here is the example:
<p style="padding: 15px; border:1px solid black;">
all four padding will be 15px
</p>

<p style="padding:10px 2%; border:1px solid black;">
top and bottom padding will be 10px, left and right padding will be 2% of the total width of the document.
</p>

<p style="padding: 10px 2% 10px; border:1px solid black;"> top padding will be 10px, left and right padding will be 2% of the total width of the document, bottom padding will be 10px </p>

<p style="padding: 10px 2% 10px 10px; border:1px solid black;"> top padding will be 10px, right padding will be 2% of the total width of the document, bottom padding and top padding will be 10px
</p>
This will produce following result:
all four paddings will be 15px
top and bottom paddings will be 10px, left and right paddings will be 2% of the total width of the document.
top padding will be 10px, left and right padding will be 2% of the total width of the document, bottom padding will be 10px
top padding will be 10px, right padding will be 2% of the total width of the document, bottom padding and top padding will be 10px

CSS - Lists

Lists are very helpful in conveying a set of either numbered or bulleted points. This tutorial teaches you how to control list type, position, style etc. using CSS
There are following five CSS properties which can be used to control lists:
  • The list-style-type Allows you to control the shape or appearance of the marker.
  • The list-style-position Specifies whether a long point that wraps to a second line should align with the first line or start underneath the start of the marker.
  • The list-style-image Specifies an image for the marker rather than a bullet point or number.
  • The list-style Serves as shorthand for the preceding properties.
  • The marker-offset Specifies the distance between a marker and the text in the list.
Now we will see how to use these properties with examples.

The list-style-type Property:

The list-style-type property allows you to control the shape or style of bullet point (also known as a marker) in the case of unordered lists, and the style of numbering characters in ordered lists.
Here are the values which can be used for an unordered list:
ValueDescription
noneNA
disc (default)A filled-in circle
circleAn empty circle
squareA filled-in square
Here are the values which can be used for an ordered list:
ValueDescriptionExample
decimalNumber1,2,3,4,5
decimal-leading-zero0 before the number01, 02, 03, 04, 05
lower-alphaLowercase alphanumeric charactersa, b, c, d, e
upper-alphaUppercase alphanumeric charactersA, B, C, D, E
lower-romanLowercase Roman numeralsi, ii, iii, iv, v
upper-roman Uppercase Roman numeralsI, II, III, IV, V
lower-greek The marker is lower-greek alpha, beta, gamma
lower-latin The marker is lower-latin a, b, c, d, e
upper-latin The marker is upper-latin A, B, C, D, E
hebrew The marker is traditional Hebrew numbering  
armenian The marker is traditional Armenian numbering  
georgian The marker is traditional Georgian numbering  
cjk-ideographicThe marker is plain ideographic numbers 
hiraganaThe marker is hiraganaa, i, u, e, o, ka, ki
katakanaThe marker is katakanaA, I, U, E, O, KA, KI
hiragana-irohaThe marker is hiragana-irohai, ro, ha, ni, ho, he, to
katakana-irohaThe marker is katakana-irohaI, RO, HA, NI, HO, HE, TO
Here is the example:
<ul style="list-style-type:circle;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>

<ul style="list-style-type:square;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>

<ol style="list-style-type:decimal;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>

<ol style="list-style-type:lower-alpha;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>

<ol style="list-style-type:lower-roman;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>
This will produce following result:
  • Maths
  • Social Science
  • Physics
  • Maths
  • Social Science
  • Physics
  1. Maths
  2. Social Science
  3. Physics
  1. Maths
  2. Social Science
  3. Physics
  1. Maths
  2. Social Science
  3. Physics

The list-style-position Property:

The list-style-position property indicates whether the marker should appear inside or outside of the box containing the bullet points. It can have one the two values:
ValueDescription
noneNA
insideIf the text goes onto a second line, the text will wrap underneath the marker. It will also appear indented to where the text would have started if the list had a value of outside.
outsideIf the text goes onto a second line, the text will be aligned with the start of the first line (to the right of the bullet).
Here is the example:
<ul style="list-style-type:circle; list-stlye-position:outside;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>

<ul style="list-style-type:square;list-style-position:inside;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>

<ol style="list-style-type:decimal;list-stlye-position:outside;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>

<ol style="list-style-type:lower-alpha;list-style-position:inside;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>

This will produce following result:
  • Maths
  • Social Science
  • Physics
  • Maths
  • Social Science
  • Physics
  1. Maths
  2. Social Science
  3. Physics
  1. Maths
  2. Social Science
  3. Physics

The list-style-image Property:

The list-style-image allows you to specify an image so that you can use your own bullet style. The syntax is as follows, similar to the background-image property with the letters url starting the value of the property followed by the URL in brackets. If it does not find given image then default bullets are used.
Here is the example:
<ul>
<li style="list-style-image: url(/images/bullet.gif);">Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>

<ol>
<li style="list-style-image: url(/images/bullet.gif);">Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>

This will produce following result:
  • Maths
  • Social Science
  • Physics
  1. Maths
  2. Social Science
  3. Physics

The list-style Property:

The list-style allows you to specify all the list properties into a single expression. These properties can appear in any order.
Here is the example:
<ul style="list-style: inside square;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>

<ol style="list-style: outside upper-alpha;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>

This will produce following result:
  • Maths
  • Social Science
  • Physics
  1. Maths
  2. Social Science
  3. Physics

The marker-offset Property:

The marker-offset property allows you to specify the distance between the marker and the text relating to that marker. Its value should be a length as shown in the following example:
Unfortunately, however, this property is not supported in IE 6 or Netscape 7.
Here is the example:
<ul style="list-style: inside square; marker-offset:2em;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>

<ol style="list-style: outside upper-alpha; marker-offset:2cm;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>

This will produce following result:
  • Maths
  • Social Science
  • Physics
  1. Maths
  2. Social Science
  3. Physics

CSS - Margins

The margin property defines the space around an HTML element. It is possible to use negative values to overlap content.
The values of the margin property are not inherited by child elements. Remember that the adjacent vertical margins (top and bottom margins) will collapse into each other so that the distance between the blocks is not the sum of the margins, but only the greater of the two margins or the same size as one margin if both are equal.
There are following four properties to set an element margin.
  • The margin A shorthand property for setting the margin properties in one declaration.
  • The margin-bottom Specifies the bottom margin of an element.
  • The margin-top Specifies the top margin of an element.
  • The margin-left Specifies the left margin of an element.
  • The margin-right Specifies the right margin of an element.
Now we will see how to use these properties with examples.

The margin Property:

The margin property allows you set all of the properties for the four margins in one declaration. Here is the syntax to set margin around a paragraph:
<style type="text/css">
p {margin: 15px}
all four margins will be 15px

p {margin: 10px 2%}
top and bottom margin will be 10px, left and right margin will be 2% of the total width of the document.

p {margin: 10px 2% -10px}
top margin will be 10px, left and right margin will be 2% of the total width of the document, bottom margin will be -10px

p {margin: 10px 2% -10px auto}
top margin will be 10px, right margin will be 2% of the total width of the document, bottom margin will be -10px, left margin will be set by the browser

</style>
Here is the example:
<p style="margin: 15px; border:1px solid black;">
all four margins will be 15px
</p>

<p style="margin:10px 2%; border:1px solid black;">
top and bottom margin will be 10px, left and right margin will be 2% of the total width of the document.
</p>

<p style="margin: 10px 2% -10px; border:1px solid black;"> top margin will be 10px, left and right margin will be 2% of the total width of the document, bottom margin will be -10px </p>

<p style="margin: 10px 2% -10px auto; border:1px solid black;"> top margin will be 10px, right margin will be 2% of the total width of the document, bottom margin will be -10px, left margin will be set by the browser
</p>
This will produce following result:
all four margins will be 10px
top and bottom margin will be 10px, left and right margin will be 2% of the total width of the document.
top margin will be 10px, left and right margin will be 2% of the total width of the document, bottom margin will be -10px
top margin will be 10px, right margin will be 2% of the total width of the document, bottom margin will be -10px, left margin will be set by the browser

The margin-bottom Property:

The margin-bottom property allows you set bottom margin of an element. It can have a value in length, % or auto.
Here is the example:
<p style="margin-bottom: 15px; border:1px solid black;">
This is a paragraph with a specified bottom margin
</p>

<p style="margin-bottom: 5%; border:1px solid black;">
This is another paragraph with a specified bottom margin in percent
</p>
This will produce following result:
This is a paragraph with a specified bottom margin
This is another paragraph with a specified bottom margin in percent

The margin-top Property:

The margin-top property allows you set top margin of an element. It can have a value in length, % or auto.
Here is the example:
<p style="margin-top: 15px; border:1px solid black;">
This is a paragraph with a specified top margin
</p>

<p style="margin-top: 5%; border:1px solid black;">
This is another paragraph with a specified top margin in percent
</p>
This will produce following result:
This is a paragraph with a specified top margin
This is another paragraph with a specified top margin in percent

The margin-left Property:

The margin-left property allows you set left margin of an element. It can have a value in length, % or auto.
Here is the example:
<p style="margin-left: 15px; border:1px solid black;">
This is a paragraph with a specified left margin
</p>

<p style="margin-left: 5%; border:1px solid black;">
This is another paragraph with a specified top margin in percent
</p>
This will produce following result:
This is a paragraph with a specified left margin
This is another paragraph with a specified top margin in percent

The margin-right Property:

The margin-right property allows you set right margin of an element. It can have a value in length, % or auto.
Here is the example:
<p style="margin-right: 15px; border:1px solid black;">
This is a paragraph with a specified right margin
</p>

<p style="margin-right: 5%; border:1px solid black;">
This is another paragraph with a specified right margin in percent
</p>
This will produce following result:
This is a paragraph with a specified right margin
This is another paragraph with a specified right margin in percent

CSS - Borders

The border properties allow you to specify how the border of the box representing an element should look. There are three properties of a border you can change
  • The border-color Specifies the color of a border.
  • The border-style Specifies whether a border should be solid, dashed line, double line, or one of the other possible values.
  • The border-width Specifies the width of a border.
Now we will see how to use these properties with examples.

The border-color Property:

The border-color property allows you to change the color of the border surrounding an element. You can individually change the color of the bottom, left, top and right sides of an element's border using the properties:
  • border-bottom-color changes the color of bottom border.
  • border-top-color changes the color of top border.
  • border-left-color changes the color of left border.
  • border-right-color changes the color of right border.
Here is the example which shows effect of all these properties:
<style type="text/css">
p.example1{
   border:1px solid;
   border-bottom-color:#009900; /* Green */
   border-top-color:#FF0000;    /* Red */
   border-left-color:#330000;   /* Black */
   border-right-color:#0000CC;  /* Blue */
}
p.example2{
   border:1px solid;
   border-color:#009900;        /* Green */
}
</style>
<p class="example1">
This example is showing all borders in different colors.
</p>
<p class="example2">
This example is showing all borders in green color only.
</p>
This will produce following result:
This example is showing all borders in different colors.
This example is showing all borders in green color only.

The border-style Property:

The border-style property allows you to select one of the following styles of border:
  • none: No border. (Equivalent of border-width:0;)
  • solid: Border is a single solid line.
  • dotted: Border is a series of dots.
  • dashed: Border is a series of short lines.
  • double: Border is two solid lines.
  • groove: Border looks as though it is carved into the page.
  • ridge: Border looks the opposite of groove.
  • inset: Border makes the box look like it is embedded in the page.
  • outset: Border makes the box look like it is coming out of the canvas.
  • hidden: Same as none, except in terms of border-conflict resolution for table elements.
You can individually change the style of the bottom, left, top, and right borders of an element using following properties:
  • border-bottom-style changes the style of bottom border.
  • border-top-style changes the style of top border.
  • border-left-style changes the style of left border.
  • border-right-style changes the style of right border.
Following is the example to show all these border styles:
<p style="border-width:4px; border-style:none;">
This is a border with none width.
</p>
<p style="border-width:4px; border-style:solid;">
This is a solid border.
</p>
<p style="border-width:4px; border-style:dashed;">
This is a dahsed border.
</p>
<p style="border-width:4px; border-style:double;">
This is a double border.
</p>
<p style="border-width:4px; border-style:groove;">
This is a groove border.
</p>
<p style="border-width:4px; border-style:ridge">
This is aridge  border.
</p>
<p style="border-width:4px; border-style:inset;">
This is a inset border.
</p>
<p style="border-width:4px; border-style:outset;">
This is a outset border.
</p>
<p style="border-width:4px; border-style:hidden;">
This is a hidden border.
</p>
<p style="border-width:4px; 
             border-top-style:solid;
             border-bottom-style:dashed;
             border-left-style:groove;
             border-right-style:double;">
This is a a border with four different styles.
</p>
This will produce following result:
This is a border with none width.
This is a solid border.
This is a dahsed border.
This is a double border.
This is a groove border.
This is aridge border.
This is a inset border.
This is a outset border.
This is a hidden border.
This is a a border with four different styles.

The border-width Property:

The border-width property allows you to set the width of an element borders. The value of this property could be either a length in px, pt or cm or it should be set to thin, medium or thick.
You can individually change the width of the bottom, top, left, and right borders of an element using the following properties:
  • border-bottom-width changes the width of bottom border.
  • border-top-width changes the width of top border.
  • border-left-width changes the width of left border.
  • border-right-width changes the width of right border.
Following is the example to show all these border width:
<p style="border-width:4px; border-style:solid;">
This is a solid border whose width is 4px.
</p>
<p style="border-width:4pt; border-style:solid;">
This is a solid border whose width is 4pt.
</p>
<p style="border-width:thin; border-style:solid;">
This is a solid border whose width is thin.
</p>
<p style="border-width:medium; border-style:solid;">
This is a solid border whose width is medium;
</p>
<p style="border-width:thick; border-style:solid;">
This is a solid border whose width is thick.
</p>
<p style="border-bottom-width:4px;
             border-top-width:10px;
             border-left-width: 2px;
             border-right-width:15px;
             border-style:solid;">
This is a a border with four different width.
</p>
This will produce following result:
This is a solid border whose width is 4px.
This is a solid border whose width is 4pt.
This is a solid border whose width is thin.
This is a solid border whose width is medium;
This is a solid border whose width is thick.
This is a a border with four different width.

Border Properties Using Shorthand:

The border property allows you to specify color, style, and width of lines in one property:
Following is the example to show to use all the three properties into a single property. This is the most frequently used property to set border around any element.
<p style="border:4px solid red;">
This example is showing shorthand property for border.
</p>
This will produce following result:
This example is showing shorthand property for border.


CSS - Tables

This tutorial will teach you how to set different properties of an HTML table using CSS. You can set following properties of a table:
  • The border-collapse Specifies whether the browser should control the appearance of adjacent borders that touch each other or whether each cell should maintain its style.
  • The border-spacing Specifies the width that should appear between table cells.
  • The caption-side Captions are presented in the <caption> element. By default, these are rendered above the table in the document. You use the caption-side property to control the placement of the table caption.
  • The empty-cells Specifies whether the border should be shown if a cell is empty.
  • The table-layout Allows browsers to speed up layout of a table by using the first width properties it comes across for the rest of a column rather than having to load the whole table before rendering it.
Now we will see how to use these properties with examples.

The border-collapse Property:

This property can have two values collapse and separate. Following is the example to show both values:
<style type="text/css">
table.one {border-collapse:collapse;}
table.two {border-collapse:separate;}
td.a {
      border-style:dotted; 
      border-width:3px; 
      border-color:#000000; 
      padding: 10px;
}
td.b {border-style:solid; 
      border-width:3px; 
      border-color:#333333; 
      padding:10px;
}
</style>
<table class="one">
<caption>Collapse Border Example</caption>
<tr><td class="a"> Cell A Collapse Example</td></tr>
<tr><td class="b"> Cell B Collapse Example</td></tr>
</table>
<br />
<table class="two">
<caption>Separate Border Example</caption>
<tr><td class="a"> Cell A Separate Example</td></tr>
<tr><td class="b"> Cell B Separate Example</td></tr>
</table>
This will produce following result:
Collapse Border Example
Cell A Collapse Example
Cell B Collapse Example

Separate Border Example
Cell A Separate Example
Cell B Separate Example

The border-spacing Property:

The border-spacing property specifies the distance that separates adjacent cells. borders. It can take either one or two values; these should be units of length.
If you provide one value it will applies to both vertical and horizontal borders Or you can specify two values, in which case the first refers to the horizontal spacing and the second to the vertical spacing:
NOTE: Unfortunately, this property does not work in Netscape 7 or IE 6.
<style type="text/css">
/* If you provide one value */
table.example {border-spacing:10px;}
/* This is how you can provide two values */
table.example {border-spacing:10px; 15px;}
</style>
Now let's modify previous example and see the effect:
<style type="text/css">
table.one {
   border-collapse:separate;
   width:400px;
   border-spacing:10px;
}
table.two {
   border-collapse:separate;
   width:400px;
   border-spacing:10px 50px;
}
</style>
<table class="one" border="1">
<caption>Separate Border Example with border-spacing</caption>
<tr><td> Cell A Collapse Example</td></tr>
<tr><td> Cell B Collapse Example</td></tr>
</table>
<br />
<table class="two" border="1">
<caption>Separate Border Example with border-spacing</caption>
<tr><td> Cell A Separate Example</td></tr>
<tr><td> Cell B Separate Example</td></tr>
</table>
This will produce following result:
Separate Border Example with border-spacing
Cell A Collapse Example
Cell B Collapse Example

Separate Border Example with border-spacing
Cell A Separate Example
Cell B Separate Example

The caption-side Property:

The caption-side property allows you to specify where the content of a <caption> element should be placed in relationship to the table. The table that follows lists the possible values.
This property can have one of the four values top, bottom, left or right. Let us see following example to show each value:
NOTE:These properties may not work with your IE Browser.
<style type="text/css">
caption.top {caption-side:top}
caption.bottom {caption-side:bottom}
caption.left {caption-side:left}
caption.right {caption-side:right}
</style>

<table style="width:400px; border:1px solid black;">
<caption class="top">
This caption will appear at the top
</caption>
<tr><td > Cell A</td></tr>
<tr><td > Cell B</td></tr>
</table>
<br />

<table style="width:400px; border:1px solid black;">
<caption class="bottom">
This caption will appear at the bottom
</caption>
<tr><td > Cell A</td></tr>
<tr><td > Cell B</td></tr>
</table>
<br />

<table style="width:400px; border:1px solid black;">
<caption class="left">
This caption will appear at the left
</caption>
<tr><td > Cell A</td></tr>
<tr><td > Cell B</td></tr>
</table>
<br />

<table style="width:400px; border:1px solid black;">
<caption class="right">
This caption will appear at the right
</caption>
<tr><td > Cell A</td></tr>
<tr><td > Cell B</td></tr>
</table>

This will produce following result:
This caption will appear at the top
Cell A
Cell B

This caption will appear at the bottom
Cell A
Cell B

This caption will appear at the left
Cell A
Cell B

This caption will appear at the right
Cell A
Cell B

The empty-cells Property:

The empty-cells property indicates whether a cell without any content should have a border displayed.
This property can have one of the three values show, hide or inherit.
Here is the empty-cells property used to hide borders of empty cells in the <table> element.
<style type="text/css">
table.empty{
    width:350px;
    border-collapse:separate;
    empty-cells:hide;
}
td.empty{
    padding:5px;
    border-style:solid;
    border-width:1px;
    border-color:#999999;
}
</style>
<table class="empty">
<tr>
<th></th>
<th>Title one</th>
<th>Title two</th>
</tr>
<tr>
<th>Row Title</th>
<td class="empty">value</td>
<td class="empty">value</td>
</tr>
<tr>
<th>Row Title</th>
<td class="empty">value</td>
<td class="empty"></td>
</tr>
</table>
This will produce following result:

Title one Title two
Row Title value value
Row Title value

The table-layout Property:

The table-layout property is supposed to help you control how a browser should render or lay out a table.
This property can have one of the three values fixed, auto or inherit.
Here is the example to show the difference between these properties.
NOTE:This property is not supported by many browsers so do not rely on this property.
<style type="text/css">
table.auto
{
table-layout: auto
}
table.fixed
{
table-layout: fixed
}
</style>
<table class="auto" border="1" width="100%">
<tr>
<td width="20%">1000000000000000000000000000</td>
<td width="40%">10000000</td>
<td width="40%">100</td>
</tr>
</table>
<br />
<table class="fixed" border="1" width="100%">
<tr>
<td width="20%">1000000000000000000000000000</td>
<td width="40%">10000000</td>
<td width="40%">100</td>
</tr>
</table>
This will produce following result:
1000000000000000000000000000 10000000 100

1000000000000000000000000000 10000000 100

CSS - Links

This tutorial will teach you how to set different properties of a hyper link using CSS. You can set following properties of a hyper link:
We will revisit same properties when we will discuss Pseudo-Classes of CSS.
  • The :link Signifies unvisited hyperlinks.
  • The :visited Signifies visited hyperlinks.
  • The :hover Signifies an element that currently has the user's mouse pointer hovering over it.
  • The :active Signifies an element on which the user is currently clicking.
Usually these all properties are kept in the header part of HTML document.
Remember a:hover MUST come after a:link and a:visited in the CSS definition in order to be effective. Also, a:active MUST come after a:hover in the CSS definition as follows.
<style type="text/css">
a:link {color: #000000}
a:visited {color: #006600}
a:hover {color: #FFCC00}
a:active {color: #FF00CC}
</style>
Now we will see how to use these properties to give different effects to hyperlinks.

Set the color of Links:

Following is the example which demonstrates how to set the link color. Possible value could be any color name in any valid format.
<style type="text/css">
a:link {color:#000000}
</style>
<a href="/html/index.htm">Black Link</a>
This will produce following black link:

Set the color of Visited Links:

Following is the example which demonstrates how to set the color of visited links. Possible value could be any color name in any valid format.
<style type="text/css">
a:visited {color: #006600}
</style>
<a href="/html/index.htm">Click this link</a>
This will produce following link. Once you will click this link, it will change its color to green.

Change the color of links when mouse is over:

Following is the example which demonstrates how to change the color of links when we bring a mouse pointer over that link. Possible value could be any color name in any valid format.
<style type="text/css">
a:hover {color: #FFCC00}
</style>
<a href="/html/index.htm">Bring Mouse Here</a>
This will produce following link. Now you bring your mouse over this link and you will see that it changes its color to yellow.

Change the color of active links:

Following is the example which demonstrates how to change the color of active links. Possible value could be any color name in any valid format.
<style type="text/css">
a:active {color: #FF00CC}
</style>
<a href="/html/index.htm">Click This Link</a>

CSS - Images

Images are very important part of any Web Page. Though it is not recommended to include lot of images but it is still important to use good images wherever it is required.
CSS plays a good role to control image display. You can set following image properties using CSS.
  • The border property is used to set the width of an image border.
  • The height property is used to set the height of an image.
  • The width property is used to set the width of an image.
  • The -moz-opacity property is used to set the opacity of an image.

The image border Property:

The border property of an image is used to set the width of an image border. This property can have a value in length or in %.
A width of zero pixels means no border.
Here is the example:
<img style="border:0px;" src="/images/css.gif" />
<br />
<img style="border:3px dashed red;" src="/images/css.gif" />
This will produce following result:
CSS Logo

The image height Property:

The height property of an image is used to set the height of an image. This property can have a value in length or in %. While giving value in %, it applies it in respect of the box in which an image is available.
Here is the example:
<img style="border:1px solid red; height:100px;" 
        src="/images/css.gif" />
<br />
<img style="border:1px solid red; height:50%;" 
        src="/images/css.gif" />
This will produce following result:


The image width Property:

The width property of an image is used to set the width of an image. This property can have a value in length or in %. While giving value in %, it applies it in respect of the box in which an image is available.
Here is the example:
<img style="border:1px solid red; width:100px;" 
        src="/images/css.gif" />
<br />
<img style="border:1px solid red; width:100%;" 
        src="/images/css.gif" />
This will produce following result:


The -moz-opacity Property:

The -moz-opacity property of an image is used to set the opacity of an image. This property is used to create a transparent image in Mozilla. IE uses filter:alpha(opacity=x) to create transparent images.
In Mozilla (-moz-opacity:x) x can be a value from 0.0 - 1.0. A lower value makes the element more transparent (The same things goes for the CSS3-valid syntax opacity:x).
In IE (filter:alpha(opacity=x)) x can be a value from 0 - 100. A lower value makes the element more transparent.
Here is the example:
<img style="border:1px solid red;-moz-opacity:0.4;filter:alpha(opacity=40);" src="/images/css.gif" />
This will produce following result: