niemie
03-13-2005, 06:45 PM
I've got a page with 2 rows of boxes, each containing a different image, and each is going to be a link to a different page. I want the images to appear somewhat dull in their "off" state and then once they are rolled over come to full color.
I have never done CSS rollovers using images, but I am guessing I would just swap out the backgrounds in a hover class to achieve what I am trying to do. This seems simple in theory but I am wondering - is there a problem with preloading images in CSS? Maybe there is a method of using only one image instead of two? Should I be thinking about hidden layers, etc or what is the easisest way to accomplish this?
Code so far:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Title Goes Here</title>
</head>
<style>
* {
margin: 0;
padding: 0;
}
body {
margin:0;
padding:0;
background-color:#cccccc;
}
a img {
border-width:0;
}
#wrapper {
width: 700px;
height: 565px;
margin-left:auto;
margin-right:auto;
margin-top:5px;
border: 1px solid #808080;
background-color:#ffffff;
}
#sidebar {
width: 123px;
height: 565px;
float: left;
background-image:url(images/sidebar.jpg);
}
#content {
margin-left: 125px;
height: auto;
width:auto;
padding: 30px;
}
h1, h2 {
font:Arial, Helvetica, sans-serif;
font-size: 24px;
font-style:oblique;
color: #444444;
}
h2 {
margin-top:100px;
}
/* Begin W Boxes */
#b1w, #b2w, #b3w {
position:relative;
float:left;
height:35px;
width:35px;
border:1px solid;
border-color: #808080;
margin-top: 5px;
margin-right: 5px;
background-color:#ffffff;
}
#b1w {
background-image:url(images/brooke.gif);
}
#b2w {
background-image:url(images/lakeo.gif);
}
#b3w {
background-image:url(images/velagio.gif);
}
/* Begin C Boxes */
#b1c, #b2c, #b3c {
position:relative;
float:left;
height:35px;
width:35px;
border:1px solid;
border-color: #808080;
margin-top: 5px;
margin-right: 5px;
background-color:#ffffff;
}
#b1c {
background-image: url(images/liveit.gif);
}
</style>
<body>
<div id="wrapper">
<div id="sidebar"></div>
<div id="content">
<h1>W Header</h1>
<div id="b1w"></div>
<div id="b2w"></div>
<div id="b3w"></div>
<h2> C Header</h2>
<div id="b1c"></div>
<div id="b2c"></div>
<div id="b3c"></div>
</div>
</div>
</body>
</html>
I have never done CSS rollovers using images, but I am guessing I would just swap out the backgrounds in a hover class to achieve what I am trying to do. This seems simple in theory but I am wondering - is there a problem with preloading images in CSS? Maybe there is a method of using only one image instead of two? Should I be thinking about hidden layers, etc or what is the easisest way to accomplish this?
Code so far:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Title Goes Here</title>
</head>
<style>
* {
margin: 0;
padding: 0;
}
body {
margin:0;
padding:0;
background-color:#cccccc;
}
a img {
border-width:0;
}
#wrapper {
width: 700px;
height: 565px;
margin-left:auto;
margin-right:auto;
margin-top:5px;
border: 1px solid #808080;
background-color:#ffffff;
}
#sidebar {
width: 123px;
height: 565px;
float: left;
background-image:url(images/sidebar.jpg);
}
#content {
margin-left: 125px;
height: auto;
width:auto;
padding: 30px;
}
h1, h2 {
font:Arial, Helvetica, sans-serif;
font-size: 24px;
font-style:oblique;
color: #444444;
}
h2 {
margin-top:100px;
}
/* Begin W Boxes */
#b1w, #b2w, #b3w {
position:relative;
float:left;
height:35px;
width:35px;
border:1px solid;
border-color: #808080;
margin-top: 5px;
margin-right: 5px;
background-color:#ffffff;
}
#b1w {
background-image:url(images/brooke.gif);
}
#b2w {
background-image:url(images/lakeo.gif);
}
#b3w {
background-image:url(images/velagio.gif);
}
/* Begin C Boxes */
#b1c, #b2c, #b3c {
position:relative;
float:left;
height:35px;
width:35px;
border:1px solid;
border-color: #808080;
margin-top: 5px;
margin-right: 5px;
background-color:#ffffff;
}
#b1c {
background-image: url(images/liveit.gif);
}
</style>
<body>
<div id="wrapper">
<div id="sidebar"></div>
<div id="content">
<h1>W Header</h1>
<div id="b1w"></div>
<div id="b2w"></div>
<div id="b3w"></div>
<h2> C Header</h2>
<div id="b1c"></div>
<div id="b2c"></div>
<div id="b3c"></div>
</div>
</div>
</body>
</html>