Forum Moderators: not2easy

Message Too Old, No Replies

Scrollable DIV changes width when hovering

IE6 bug? Have to set scrollable DIV to 70%

         

ozaru

9:48 pm on Sep 14, 2007 (gmt 0)

10+ Year Member



I have a page containing a scrollable DIV with the type of code shown below:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="test.css" rel="stylesheet" type="text/css" >
</head>
<body>
<div id="Content">
<div style="width:70%; height:150px; border:solid; overflow:scroll;">
ABC <a href="ABC">ABC</a> ABC
</div>
</div>
</body>
</html>

The stylesheet test.css contains for example only:

a:hover {background-color:#ccc;}
#Content {margin: 30px 50px 50px 200px;}

When I load this in IE6 and then hover over the link, the DIV suddenly gets wider. In some situations it returns to the normal width when I move the mouse away from the link, but sometimes it doesn't. The result is that I have to space the DIV at 70% width because otherwise it overshoots the width of the screen!

Can anyone see a problem in the code, and/or how to fix it? A friend tested this on Opera & Mozilla and said they did not exhibit this behaviour, so maybe it's an IE6 bug... but still, a workaround would be appreciated. TIA

Xapti

3:41 am on Sep 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Quirky behaviour from IE yes, but it's not entirely IE's fault.

The problem seems to be that you have width:70% assigned to the inner div, but no where else do you have any widths assigned! you also don't have a "containing block" established, which is required to inherit attributes like that.
[w3.org...]
[w3.org...]

ozaru

7:21 am on Sep 15, 2007 (gmt 0)

10+ Year Member



OK, I think I see this. The CSS line

#Content {margin: 30px 50px 50px 200px;}

is effectively shifting that DIV box down and to the right (which I want), with its right margin extending beyond the original right margin of the screen (which I don't want).

What I want is that DIV (Content) to be 30px down & 200 px right, but for the right margin to remain at the screen's width. Then I want the inner DIV (containing the ABC links) to fill that width (but have a border and be scrollable). I suspect the second half will be easy once the first half works properly. Something like:

#Content {margin: 30px 50px 50px 200px; width: 100%_of_original_body_minus_250px}

<div id="Content">
<div style="width:100%; height:150px; border:solid; overflow:scroll;">
ABC <a href="ABC">ABC</a> ABC
</div>
</div>

Any advice on how to achieve this? I could put an absolute width for Content but don't want to as I'd prefer it to scale to match the user's screen width. I am looking through the W3 "containing block" links suggested, but it's taking a while to absorb and I haven't yet found a solution.

ozaru

8:00 am on Sep 15, 2007 (gmt 0)

10+ Year Member



Thought I had it for a moment then...

<body width=100%>
<div id="Content" style="border:solid;">
<div style="width:73%; height:150px; border:solid; overflow:scroll;">
ABC <a href="ABC">ABC</a> ABC
</div>
</div>
</body>

a:hover {background-color:#ccc;}
#Content {margin: 30px 50px 50px 200px;}

This seems to have the DIV Content at the width I require, i.e. 200px on the left and the right matches the original screen width. However, the inner DIV still suddenly expands whenever I hover over the link: at 73% it matches the outer Content DIV, at less than 73% it leaves a gap, and at over 73% it crashes through the right-hand boundary. :(

ozaru

8:22 am on Sep 15, 2007 (gmt 0)

10+ Year Member



Doh! I don't believe it. Either something has gone very strange on my system, or I've solved it simply by removing all references to width, from both DIVs and from BODY. No more flicking open & closed, no more erratic behaviour -- and the widths all default to AUTO, which works fine. Why on earth did I include the width references in the first place? I can't remember...

Anyway, I hope this helps someone else who comes across similar behaviour.