![]() |
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"> |
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>Code:
a img { border: 2px solid #fff; }Code:
a:hover img { border: 2px solid #000; }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; }Good luck. |
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.
|
So you can't give the anchor nor the image a classname?
|
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>}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 |
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 :). |
*kidnaps IE6 and dumps it off a bridge*
|
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"> |
Quote:
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 |
Quote:
edit:/ 9.5 is an excelent start! |
Quote:
I've really been meaning to try opera out one of these days. |
Thanks to everyone for trying to help. I didn't realize it was such a difficult problem.
|
I just wanted to followup on this since I finally figured it out and thought someone might need to know how to do it at some point.
The original code I used works for the most part. All I had to do was change the border-style: none; to border-style: double; for the plain classes and make the border color white. That way, the border is really being drawn all of the time for each box, thus preventing the size to change. On the mouseover, the color is changed and the border appears. Works well in IE and FireFox. |
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.
|
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 |
| All times are GMT. The time now is 10:03 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0