简体   繁体   中英

CSS rollover problems with Internet Explorer 7

I wrote some CSS in my HTML code to create rollover buttons. Then i tried to run it with IE 7 and surprise! it doesn't run. In fact it shows both the button and underlying rollover. How can i get around IE's inability to cache background images? Preferably using CSS but javascript 'will' be tried.

Sample CSS:

 #Menu 
 { 
    width: 100%; 
    height: 32px; 
    margin-top: 93px;
    padding-left: 13px;
}


 #Menu a 
{ 
    height: 32px; 
    line-height: 32px; 
    width: 123px; 
    background: url("img/menu.png") top left no-repeat; 
    background-position: -123px 0; 
    float: left; 
    margin-left: 3px; 
    text-decoration: none; 
    color: #1e1e1d; 
    font-size: 12px; 
    text-align: center; 
}

 #Top #Menu a:hover, #Top #Menu a.active 
{ 
    background-position: 0px 0; 
    text-decoration: underline;
}

Well firstly you are giving conflicting instructions ...

background: url("img/menu.png") top left no-repeat;
background-position: -123px 0;

... the background is already positioned using shorthand.

I assume that your regular and hover states both share the same image, so why not do both with shorthand? Remove...

background-position: -123px 0;

... and for your hover and active states, use ...

background-position: bottom left;

Then have both your states in one image, one below the other (which I assume is what you've been trying anyway).

Image rollover issue comes mainly because of downloading image every time on hovering a link or tab. This flicker is caused by the delay when the primary image is removed and the rollover image is loaded (even though they are technically the same image, Internet Explorer prefers to treat them separately).

check it out complete fix for rollover issue: http://faqspoint.blogspot.com/2011/12/ie-rollover-problem.html

if you are using the :hover pseudo-selector, then it won't work in IE unless it is an anchor tag. Try changing the button into an anchor. You can still make it look like a button using css.

If you want to use javascript, then have a look at jQuery .

Try making sure your CSS background syntax is correct. Some browsers let you specify the properties in any order however IE will choke. You should specify the attachment in the form XY (horizontal then vertical). You currently have top left . Make it left top . Also you have no-repeat at the end of the line, it should come just after the url declaration and before the position declaration.

The order for CSS background shorthand values should be:

  • background-color
  • background-image
  • background-repeat
  • background-position
  • background-attachment

eg. background: #fff url(example.jpg) no-repeat left top fixed;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM