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 300x114 Tutorial: how to attach an image to a link in css

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 300x168 Tutorial: how to attach an image to a link in css

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

 

Like this post? Share it!

digg 48 Tutorial: how to attach an image to a link in css reddit 48 Tutorial: how to attach an image to a link in css stumbleupon 48 Tutorial: how to attach an image to a link in css delicious 48 Tutorial: how to attach an image to a link in css furl 48 Tutorial: how to attach an image to a link in css technorati 48 Tutorial: how to attach an image to a link in css google 48 Tutorial: how to attach an image to a link in css myspace 48 Tutorial: how to attach an image to a link in css facebook 48 Tutorial: how to attach an image to a link in css twitter 48 Tutorial: how to attach an image to a link in css
share save 171 16 Tutorial: how to attach an image to a link in css

No related posts.

About liwun

Beautiful lady who has the passion for drawing. Fun and lovable. She writes mostly on Adobe illustrator categories and is one of the first guest author of Hungred.com. You can see a lot of drawing produce by her on her personal blog. She is also the founder of 1sitedaily
This entry was posted in CSS, How-to and tagged . Bookmark the permalink.

Comments are closed.