鼠标经过导航变换背景,只用一张图片进行移位显示

发布时间:2009年05月11日      浏览次数:1517 次
当鼠标移到超链接上时,更换背景,本功能只需要一张背景图片(daohang.jpg)。
需要注意是:该图片为一张同时具有原背景与要变换的背景,原背景在上,要变换的背景紧接着在原背景之下,高度自已调整。
原理:将导航外的div设为原背景,高度为原背景的高度,原超链接默认无背景,当鼠标移到超链接上时,将该背景图片动态赋予超链接,并且将位置向上移动原背景的高度,即显示了原背景下面要变换的背景了。
<style type="text/css">
      .top_daohang{ clear:both; width:100%; height:24px; line-height:24px; background: url(daohang.jpg) top left no-repeat; margin:0; padding:0px; white-space:nowrap; display:block; }
      .daohang_active{ background-image: url(daohang.jpg); background-repeat: no-repeat;}
      .top_daohang a{ float:left; color:#666; height:24px; list-style:none; display:inline; margin:0; padding:0px; color:#000; font-size:12px; font-weight:bold; text-decoration:none; text-align:center;}
      .top_daohang a:hover{ text-decoration:none; background-image: url(daohang.jpg); background-repeat: no-repeat;}
      .top_daohang a:visited{ color:#666;}
      .top_daohang .top_daohang_item_over1 { width:70px; background-position: -55px -26px; margin-left:55px; color:#666;}
      .top_daohang .top_daohang_item_over2 { width:100px; background-position: -125px -26px; color:#666;}
      .top_daohang .top_daohang_item_over3 { width:105px; background-position: -225px -26px; color:#666;}
</style>
<div class="top_daohang">
      <a href="#" class="top_daohang_item_over1 daohang_active">导航一</a>
      <a href="#" class="top_daohang_item_over2">导航二</a>
      <a href="#" class="top_daohang_item_over3">导航三</a>
</div>
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!