Forum Moderators: not2easy

Message Too Old, No Replies

Problem in IE7 with mouse hover over menu

Extra background during mouse hover

         

kiwibrit

3:25 pm on Sep 29, 2008 (gmt 0)

10+ Year Member



When hovering the mouse over the side menu, the background and text color change as expected - in IE 7 and 8, and in FF, Safari, Opera and Google Chrome. However, in IE7 only, the when the mouse is hovered over the button, a band of the original button background color appears beneath the button and its borders (the full width of the button).

I am trying to get rid of that with a conditional statement, buyt am foxed. Any suggestions?

DOCTYPE

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

CSS


body {
font-family:Arial, Helvetica, sans-serif;
color:#000099;}
#sidenavbar {
font-family:Arial, Helvetica, sans-serif;
font-size:.8em;
line-height:1.2em;
float:left;
width:100px;
margin-left:0;
margin-top:.5em;
margin-bottom:1em;
}
#sidenavbar ul {
list-style:none;
margin:0;
padding:0;
}
#sidenavbar ul a {
width:auto;
}
#sidenavbar ul li {
background-color:#000099;
margin-bottom:.5em;
}
#sidenavbar a {
padding:2px 0 2px 10px;
text-decoration:none;
display:block;
width:100%;
border-bottom: solid .1em #fff;
border-top: solid .1em #fff;
border-left: solid .1em #fff;
border-right: solid .1em #fff;
}
#sidenavbar a:link,#sidenavbar a:visited {
color:#fff;
}
#sidenavbar a:focus, #sidenavbar a:hover {
color: #000000;
background-color:#FFFF00;
}
#sidenavbar ul li a:hover{
background-color:#FFFF00;
margin-bottom:.5em;
}

HTML


<div id="sidenavbar">
<ul>
<li>
<a href="#">This</a>
</li>
<li>
<a href="#">That</a>
</li>
<li>
<a href="#">Other</a>
</li>
</ul>
</div>

kiwibrit

5:09 pm on Sep 29, 2008 (gmt 0)

10+ Year Member



This fixed it - any idea why?:

CSS


<!--[if IE 7]>
<style type="text/css">
#sidenavbar ul li a:hover{
background-color:#FFFF00;
margin-bottom:0;
}
</style>
<![endif]-->

alt131

7:46 pm on Sep 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Applying a border to
#sidenavbar ul a OR #sidenavbar ul li
AND
#sidenavbar ul li a:hover
produces the same effect in ie6, Opera9, winSafari and FF3 as well as ie7 (Chrome and ie8 not tested).

The culprit is
#sidenavbar ul li a:hover {
margin-bottom:0.5em;
}
because this adds a bottom margin on hover only. Box model interpretations etc mean this is not visually noticeable in some browsers until the borders are added.

Your conditional comment fixes the issue in ie7 because it removes the margin-bottom applied in the main style sheet. However, on the provided code there doesn't seem any reason to apply

margin-bottom
to
#sidenavbar ul li a:hover
to start. So my suggestion would be to just remove it from the main style sheet, rather than declaring it, then removing it for individual browsers.

kiwibrit

11:36 pm on Sep 29, 2008 (gmt 0)

10+ Year Member



In practice the CSS I posted works fine in IE8, Safari, Opera, FF3, and Google Chrome.

If I change the CSS to

#sidenavbar ul li a:hover{
background-color:#FFFF00;}

The background color no longer changes in IE8 - though it does in other browsers. Effectively, there is a bug in IE8 which is overcome by specifying the bottom margin - even for zero margin.

So

[code]
#sidenavbar ul li a:hover{
background-color:#FFFF00;
margin-bottom:0;
}

cracks it for IE7, IE8, and all sensible browsers.

Thank you for getting back to me.