 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
06-26-2008, 02:08 AM
|
#1 (permalink)
|
|
The Contributor
Join Date: Apr 2008
Posts: 78
Thanks: 0
|
How to prevent jumping on rollover
I'm trying to display a box around images as the user mouse's over them. The code works but the images jump. Here is a link to an example http://64.22.87.10/~codetest/rollover/test.html And here is the code used on that page. I would appreciate any thoughts on what the problem is. (Note that the tables are not my decision and must be used.)
HTML Code:
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html dir="ltr" lang="en">
<head>
<style type="text/css">
.bgrollover {
background-color: #fff;
border-style: double;
font-size: 10px;
font-family: Verdana, Arial, Helvetica, sans-serif;
text-decoration: none;
}
.bgrolloverPlain {
background-color: #fff;
border-style: none;
font-size: 10px;
font-family: Verdana, Arial, Helvetica, sans-serif;
text-decoration: none;
}
a.bgrollover, a.bgrolloverPlain {
background-color: #fff;
border-style: none;
font-size: 10px;
font-family: Verdana, Arial, Helvetica, sans-serif;
text-decoration: none;
}
a.bgrollover:hover, a.bgrolloverPlain:hover {
background-color: #fff;
font-size: 10px;
font-family: Verdana, Arial, Helvetica, sans-serif;
text-decoration: none;
}
</style>
</head>
<body>
<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td><table border="0" width="30%">
<tr>
<td class="bgrolloverPlain" align="center" onMouseover="this.className='bgrollover'" onMouseout="this.className='bgrolloverPlain'"><img src="imgb.jpg" width="250" alt=""><br>Premium Quality</td>
</tr>
</table></td>
<td><table border="0" width="30%">
<tr>
<td class="bgrolloverPlain" align="center" onMouseover="this.className='bgrollover'" onMouseout="this.className='bgrolloverPlain'"><img src="imgc.jpg" width="250" alt=""><br>Prestige Quality</td>
</tr>
</table></td>
<tr>
</table>
</body>
</html>
|
|
|
|
06-26-2008, 09:26 AM
|
#2 (permalink)
|
|
The Acquainted
Join Date: Oct 2007
Posts: 170
Thanks: 18
|
Personally, I would do it with css only.
Create an image with an anchor:
(The anchor is for the hovering, IE can only hover anchors)
HTML Code:
<a href=";"><img src="img.jpg" width="20" height="20" alt="" /></a>
Give the image a the same color border as the background (for instance, white):
Code:
a img { border: 2px solid #fff; }
Now to the hovering part:
Code:
a:hover img { border: 2px solid #000; }
As you can see, it works well in FF!
As usual, in IE this won't work, so you have to put a little 'hack' on the a:hover, like this:
Code:
a:hover { color: red; }
Now it works cross-browser without the picture moving!
Good luck.
|
|
|
|
06-26-2008, 11:55 PM
|
#3 (permalink)
|
|
The Contributor
Join Date: Apr 2008
Posts: 78
Thanks: 0
|
Thanks for the suggestion. I had cut the code down to try to present the problem in the least possible terms. In actuality, this is a php site and the image is already a link so, as far as I know, I can't use the code you suggested since I can't add the anchor. And wouldn't the img class affect all images? That would not be correct.
|
|
|
|
06-27-2008, 09:42 AM
|
#4 (permalink)
|
|
The Acquainted
Join Date: Oct 2007
Posts: 170
Thanks: 18
|
So you can't give the anchor nor the image a classname?
|
|
|
|
06-27-2008, 01:19 PM
|
#5 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
The way maZtah wrote that, the snippet would only affect images inside of an A-nchor tag. <a href...>
Code:
a img { #images inside A <a href...><img></a>}
img { #all images <img>}
img.imgClass { #any images with the class 'imgClass' <img class="imgClass" ...> }
div#menu img { #only images located inside a div with the id of 'menu' <div id="menu"><img></div>}
See how that works?
If the image is already a link you shouldn't have any problem implementing maZtah's fix. I would also suggest using straight CSS to do this instead of javascript, especially in this case it's highly unnecessary and redundant considering css already allows you to add the :hover pseudo selector.
If the code above was exactly how it was going to be used, this is how I'd write the same fix (without the javascript);
Code:
td.bgrolloverPlain img
{
border : 3px double #FFF;
}
td.bgrolloverPlain img:hover
{
border: 3px double #000;
}
|
|
|
|
06-28-2008, 04:23 PM
|
#6 (permalink)
|
|
The Acquainted
Join Date: Oct 2007
Posts: 170
Thanks: 18
|
That's the best css-code, but IE(6) does only allow the :hover on an anchor. That's why I put an <a> around the image.
Anyways, I think Benton can fix his issue now :).
|
|
|
|
06-28-2008, 07:06 PM
|
#7 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
*kidnaps IE6 and dumps it off a bridge*
|
|
|
|
07-17-2008, 01:48 AM
|
#8 (permalink)
|
|
The Contributor
Join Date: Apr 2008
Posts: 78
Thanks: 0
|
I am still trying to get this to work. I've implemented the changes mentioned here, although I'm not sure I did them correctly. I've updated the code on the page so the result can be seen there and the code is below. It is better than the original, as far as the image moving is concered but the text is not included in the box now, the text moves up and down and the box around the image is missing the right side. I'm a novice at css, in case it isn't obvious, and I have put a lot of effort into getting this to work but I'm lost. Would someone please take another look and let me know where I have gone wrong?
HTML Code:
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html dir="ltr" lang="en">
<head>
<style type="text/css">
a imgA { border: 2px solid #fff; }
a:hover imgA { border: 2px solid #000; }
td.bgrolloverPlain img
{
border : 3px double #FFF;
}
td.bgrolloverPlain img:hover
{
border: 3px double #000;
}
a.bgrolloverPlain {
border: 3px double #fff;
text-decoration: none;
}
a.bgrolloverPlain:hover {
border: 3px double #000;
text-decoration: none;
}
</style>
</head>
<body>
<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td><table border="0" width="100%">
<tr>
<td class="bgrolloverPlain" align="center" width="33%" valign="top"><a class="bgrolloverPlain" href="http://domainname"><img class="imgA" src="imgb.jpg" width="250" border="0"><br>Classic Quality ( I1-I2 ) 14K<br>Gold Diamond Solitare Stud<br>Earring</a></td>
</tr>
</table></td>
<td><table border="0" width="100%">
<tr>
<td class="bgrolloverPlain" align="center" onMouseover="this.className='bgrollover'" onMouseout="this.className='bgrolloverPlain'"><a class="bgrolloverPlain" href="http://domainname"><img class="imgA" src="imgc.jpg" width="250" border="0"><br>Premium Quality ( Si1-Si2 )<br>14K Gold Diamond Solitare Stud<br>Earring</a></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
|
|
|
|
07-17-2008, 01:31 PM
|
#9 (permalink)
|
|
The Acquainted
Join Date: May 2008
Posts: 175
Thanks: 9
|
Quote:
Originally Posted by delayedinsanity
*kidnaps IE6 and dumps it off a bridge*
|
If you need a body bag, let me know.
Really though, I love the :hover selector. I have input elements that change color slightly based on selection. I'll be damned if I am going to write something custom just for a pretty affect though for the IE users. In all reality, its just more time to promote firefox :D
__________________
There are No Stupid Questions. But there a LOT of Inquisitive Idiots.
|
|
|
07-17-2008, 01:56 PM
|
#10 (permalink)
|
|
The Addict
Join Date: Nov 2007
Location: the Netherlands
Posts: 281
Thanks: 2
|
Quote:
Originally Posted by drewbee
In all reality, its just more time to promote [s]firefox[/s] Opera :D
|
Fixed. >:)
edit:/ 9.5 is an excelent start!
__________________
Nunchaku! Who doesn't like martial arts? =)
Last edited by Jim : 07-17-2008 at 02:31 PM.
|
|
|
07-17-2008, 02:10 PM
|
#11 (permalink)
|
|
The Acquainted
Join Date: May 2008
Posts: 175
Thanks: 9
|
Quote:
Originally Posted by Jim
Fixed. >:)
|
hah!
I've really been meaning to try opera out one of these days.
__________________
There are No Stupid Questions. But there a LOT of Inquisitive Idiots.
|
|
|
07-23-2008, 10:57 PM
|
#12 (permalink)
|
|
The Contributor
Join Date: Apr 2008
Posts: 78
Thanks: 0
|
Thanks to everyone for trying to help. I didn't realize it was such a difficult problem.
|
|
|
|
07-27-2008, 09:33 PM
|
#13 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
|
You do know that an outline is the same as a border, and it doesn't move the element, right? You could have just made that one element use an outline.
__________________
Signatures are nothing but incriminating.
|
|
|
07-27-2008, 10:08 PM
|
#14 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
The problem is, as usual, internet explorer doesn't properly support the outline property. So you need to use border if you want it to be cross-browser.
-m
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|