Tutorial: how to attach an image to a link in css

First I made an unordered list in my html body with two links that I wanted. Here's an example below.

<div>
<ul>
	<li id="girl">
		<a href="http://looliwun.com">looliwun</a>
		</li>
	<li id="boy">
		<a href="http://hungred.com">hungred</a>
		</li>
		</ul>
</div>

This would result in a basic unordered list.

link1

I styled it in css using two pictures I made with Photoshop

ul
{
list-style: none; /*removes the underline below the link*/
margin: 0; /*removes the margin*/
padding: 0; /*removes the padding*/
}

ul li
{
float: left; /*this makes the element displays in a horizontal line*/
margin: 0;
padding: 0;
}

ul li a
{
color: #777;
display: block;  /*The element will be displayed as a block level element */
width: 75px; /*This allows the picture to be fit in the block*/
padding: 60px 10px 5px; /*There is 60px of padding on the top, 10px of padding on the right and left, and 5px of padding on the bottom*/
text-align: center;
text-decoration: none; /*removes all text decoration*/
}

ul li#girl a
{
background: transparent url(blablabla_files/rabbit.png) no-repeat top center; /*this makes the picture appears in the top center without any repeats*/
}

ul li#boy a
{
background: transparent url(blablabla_files/rawr.png) no-repeat top center;
}

ul li#girl a:hover,
ul li#boy a:hover
{
background-color: #FFFBC6;
/*this makes the color of the text change when the mouse hovers over the link*/}

ul li a:hover
{
color: #000 /*this makes the color of the text change when the mouse hovers over the link*/
}

This would make my link look like this
link2

When my mouse hovers over the link, the background colour changes to yellow, and the text of the link changes from gray to black.

Tutorial: How to create columns using the div tag

First, I created a container div that would hold everything in my layout. My CSS container rule was

#container
{
width: 800px;
text-align: left;
margin: 0 0 0 150px;

}

Next, within the HTML container div, I inserted a div for the content column and a div for the navigation column


content

Within the CSS rules, my content column was

#content
{    width: 65%;
float: left;
}

whereas my navigation column was

#navigation
{
width: 30%;
margin-left: 70%;


}

This makes my file look like this

html

CSS: Box Model Problem/Hack

The problem caused by different browsers way of interpreting a CSS element has emerge the need of CSS hack. The box model hack was developed by Tantek Celik, the lead developer of Internet Explorer for the Mac to solve the issue on IE 5 border and padding problem. The total width of the box SHOULD be calculated by adding the border thickness on the left and right, the padding on the left and right and the width of the content. Thus, Consider the following code:

<code>#test{
background: #ff8132;
border: 5px solid #ff0000;
padding: 15px;
width: 100px;
}
</code>

The above code should create a box with a 5-pixel border and 15 pixels of padding around the content which has a 100 pixel width. This gave a total width of 140 pixels.

Unfortunately, some common browsers ( IE 6 and below) interpret this code incorrectly, Instead of applying the width to the content area, the width restrains the overall box size, so that the border and padding subtracted from the over width! So we are left with a box 100pixels width, but a content area only 60 pixel wide!!( width - left and right border+padding = 60 pixel)

This cause cross browser issues when displaying the same box on for example, IE and Firefox! Firefox will display a box of total width 140 pixel while IE will only display the same box with a total width of 100 pixel! To fix this, we need to use a hack, that is, we have to intentionally introduce code that doesn't work in one browser so that both boxes have the same width.(writting  a code that work in IE but fail in firefox so that both of them have 140 pixel)

We will be taking advantage of a bug in IE that causes it to ignore certain CSS so that it set the true width:

<code>#test{
background: #ff8132;
border: 5px solid #ff0000;
padding: 15px;
<span style="color: #ff0000;">voice-family: "\"}"\";
voice-family: inherit;</span>
width: 100px;
}
</code>

But this will caused problems in Opera unless we add a definition after the above code

<code>html>body #test{
width: 100px;
}</code>

This allows browsers that understand the parent/child selector grouping to correctly interpret your code. Nowadays, with IE 7 came along, this problem will not be shown on the newer browser but for older browser on old pc this is still a problem. Other than the box model problem, presently there are still problems exist on today browsers due to different implementation and interpretation by these browsers. The need of CSS hack is still needed so that cross browser issues caused by CSS can be eliminated.