CSS实现鼠标移到图片上显示大图

08-03-04 12:51   View:770

写了一个css:

a.ShowImg{position:relative;}
a.ShowImg b{display:none;}
a.ShowImg:hover b
{
display:inline;
padding:2px 3px;
position:absolute;
top:15px;
width:120px;
background:#FDFBDF;
border:1px solid #000;
text-align:left;
line-height:14px;
color:#000000;
font-weight:normal;
}


xhtml中如下:

<a class="ShowImg" target="_self" href="http://www.baidu.com/" ><b><img src="http://www.baidu.com/img/slogo-03renwu.gif" border=0></b><img src="http://www.baidu.com/img/logo-yy.gif" border=0></a>


提出的问题
1、firefox下可以正常显示
2、IE7下也可以正常显示
3、IE6下无法显示

解决方案及原因

解决:在CSS中加上一句:将background:#FDFBDF;加入到a.ShowImg:hover中.
a.ShowImg:hover{background:#FDFBDF;}

原因:hover属性在CSS1标准中仅仅支持a标签,而在hover属性在css2标准中对大部分对象都支持。

这里使用一个background属性来消除伪类。

再用其他属性进行设置:例如width,positon,background,text-decoration等等,发现除了text-decoration,color,z-index不能触发显示外,其他属性均可以做为消除伪类:hover的特定属性。

于是最终样式如下:

a.ShowImg{position:relative;}
a.ShowImg b{display:none;}
a.ShowImg:hover b
{
display:inline;
padding:2px 3px;
position:absolute;
top:15px;
width:120px;
background:#FDFBDF;
border:1px solid #000;
text-align:left;
line-height:14px;
color:#000000;
font-weight:normal;
}
a.ShowImg:hover{background:#FDFBDF;}

 

Feedback


  • No comments posted yet.
Title:
 
Name:
 
URL:

Comments:
 

Because of the cache,you may see your comments several minutes later.


Main Feeds

Copyright © 2003-2007 by 方继祥