【问题标题】:CSS hover image link not working in Internet ExplorerCSS 悬停图像链接在 Internet Explorer 中不起作用
【发布时间】:2011-11-28 21:25:09
【问题描述】:

请参考http://solarisdutamas.com/fb/KonzeptGarden/sample.php,将鼠标移至“Pebbles Wash”并点击图片。它在 Chrome 和 Firefox 中运行良好,但链接在 IE 中不起作用。 这是我的代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Konzept Garden</title>
<style type="text/css">
* {margin: 0; padding: 0;}
#main {
width: 520px;
height: 228px;
background-image: url(stone.jpg);
background-repeat: no-repeat;
position: relative;
margin: 0 auto;}

#main ul li {
list-style: none;
display: inline;}

#main ul li:hover {
visibility: visible;}

#main ul li a {
position: absolute;
z-index: 1;}

#main ul li a:hover {
z-index: 100;}

#main ul li img {
position: absolute;
top: 300px;
right: 999em;}

#submain1 .butt1 a {
left: 8px;
top: 80px;
    width: 90px;
height: 32px;}

#main ul .butt1:hover img {
    left: 8px;
    top: 80px;}
</style>
</head>
<body style="margin: 0px; width: 520px;">
<div id="main">
<ul id="submain1">
<li class="butt1"><a href="http://konzeptstone.com/p_pebbles.html" target="_blank"></a><img src="p1.png"></li>
</ul>
</body>
</html>

有谁知道为什么这在 IE 中不起作用?

【问题讨论】:

    标签: css image internet-explorer hyperlink hover


    【解决方案1】:

    如果您安装了 jQuery,一个选项是使用它。就像 Jason 所说, :hover 在 IE6 及更低版本中不起作用,除了锚点之外的任何东西。

    假设你可以使用 jQuery,解决方案是:

    $('#main ul li').hover(function(){
      $(this).show();
    });
    

    另一个使用 jQuery 的选项是在 Hover 上动态添加一个类。

    $('#main ul li').hover(function(){
      $(this).addClass('hoverState');
    });
    

    然后 CSS 将是:

    #main ul li.hoverState {
    visibility: visible;}
    

    【讨论】:

      【解决方案2】:

      我知道这有点矫枉过正,但这将确保它即使在 I.E. 上也能正常工作。 6:

      #submain1 .butt1 a:link, a:active, a:visited {
         left: 8px;
         top: 80px;
         width: 90px;
         height: 32px;
         display:block;
         overflow: hidden;
      }
      

      然后:

      <li class="butt1"><a href="http://konzeptstone.com/p_pebbles.html" target="_blank">&nbsp;</a><img src="p1.png"></li>
      

      .

      【讨论】:

        【解决方案3】:

        如果您使用的是早期版本的 IE,:hover 会出现问题。

        http://reference.sitepoint.com/css/pseudoclass-hover

        【讨论】:

          猜你喜欢
          • 2014-02-01
          • 2011-07-22
          • 1970-01-01
          • 2012-09-21
          • 2013-04-28
          • 2012-11-06
          • 1970-01-01
          • 2013-07-03
          • 1970-01-01
          相关资源
          最近更新 更多