-
Over here i learned how to do image transparency with onmouseover and onmouseout, but it only deals with inline coding. is there a way i can apply this to an external style sheet?
I want to make a navigation bar that increases opacity when you put your cursor over it. Right now i applied a transparent background to a navigation cell from an external style sheet, like so:
.navcell{
width:150px;
height:40px;
text-align:center;
background-image:url("images/test.jpg");
opacity: 0.2;
}
i tried to add the onmouseover and onmouseout attributes to this style sheet, but it didnt seem to work. is this possible? can you suggest any other solutions?
-
Your .navcell is your "onmouseout" (which doesn't exist with CSS but since it's your frame of reference I'm using it.
To apply "mouseover" attributes, you want .navcell:hover {and then your CSS goes here}.
Edit: that particular example isn't a very good one. Translucency usually works best with images that are already translucent i.e. PNGs with an alpha transparency of some sort.
-
So it's the same as the a:link, a:visited, a:hover, and a:active?
-
The same, assuming .navcell refers to an anchor (there are differences if .navcell is say a div, although "hover" will also work in most browsers).
-
It's a table cell. I'm using a table for my navigation bar. What i was going to do is this:
-Make a table with one row and 5 cells (for each of the nav items)
-Insert an image into each of the cells.(Home, About, Contact etc.)
-Attach links to the images
-Make it so that the images become more transparent when you hover your cursor over them.
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Victoria's Massage Therapy</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
<head>
<body>
<div id="container">
<div id="banner">
</div>
<div id="navbar">
<table border="1" align="center">
<tr>
<td class="navcell"><a href="index.html">Home</a></td>
<td class="navcell"><a href="about.html">About Me</a></td>
<td class="navcell"><a href="types.html">Types of Massage</a></td>
<td class="navcell"><a href="prices.html">Prices</a></td>
<td class="navcell"><a href="contact.html">Contact Me</a></td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
[CSS]
body{
background-color: #d4f7df;
}
#container{
margin:0 10% 10px 10%;
position:absolute;
width:1000px;
height:800px;
z-index:-1;
border: 2px dotted red;
}
#banner{
width: 1000px;
height: 200px;
z-index:1;
border: 1px dotted blue;
}
#navbar{
width:1000px;
height:50px;
border:1px dotted green;
}
.navcell{
padding: 0;
width:150px;
height:40px;
text-align:center;
background-color:#ededde;
opacity: 1;
}
.navimage{
}
[/CSS]
-
Well, kid, if you noticed in your "intro" thread, I mentioned that you might have to unlearn something you were taught in school. This is exactly what I was talking about.
First of all, you should never...EVER...use a table for laying out anything other than...well, data. If it wouldn't be displayed in a spreadsheet or database table, it shouldn't be displayed in a table on a web page. Tables create messy code and can also cause other problems.
For a menu, you should use a horizontal unordered list. Here's a simple example to get you started. What I would actually suggest as far as your images go is to create your "off" and "over" images in Photoshop (your "over" images containing the greater transparency) and use CSS to generate the "flip" effect.
The bottom of this tutorial will give you the idea for the flip effect, except that you're going to be using an unordered list (because that's what a menu effectively is...a list of links) instead of a p tag.
There's a more advanced technique that uses sprites, but you'll want to take this a small chunk at a time.
-
Thanks a lot! I will try that method now :D
-
I got another question while coding this.. How do you know the size of the image to create, since the size of the <li> box isn't directly controllable?
-
li {width: (whatever you want)} <-- You can control the size.
As far as what size of image to create, "whatever fits nicely". That depends on the menu item and the text inside it, though. There's no real universal answer.