jquery - 使用 CSS 导航翻转并应用 jQuery

标签 jquery css navigation rollovers

我想知道如何为我的导航栏创建翻转,并且如果可能的话,一旦导航悬停,我还应用一些 JQuery 将不透明度设置为 0 到 100。

悬停时我的导航。字母中的光芒。

alt text

HTML:(忽略空的 div)

<nav>
    <ul>
      <div class="ref1"><!-- empty div for reflections --></div>
      <li><a href="#">Home</a></li>
      <li><a href="#">About Us</a></li>
      <li><a href="#">Client Login</a></li>
      <li><a href="#">Support</a></li>
      <li><a href="#">Contact</a></li>
      <div class="ref2"><!-- empty div for reflections --></div>
    </ul>
  </nav>

CSS:

nav { background: #282828 url(../images/nav-bg.png) repeat-x; border-radius: 6px; -webkit-border-radius: 6px; -moz-border-radius: 6px; -o-border-radius: 6px; margin: 24px auto;  width: 638px; }
nav ul { padding: 18px 0;  }
nav ul li { background: url(../images/nav-sep.jpg) left center no-repeat; display: inline; padding: 32px; margin: 0 auto;  }
nav ul li:first-of-type { background: none; }
nav ul li:last-of-type { background: url(../images/ref2.png) no-repeat right bottom; margin: 10px 0 0 0; }
nav ul li a { color: #626262; font: 16px Arial, Helvetica, serif; }
nav ul li a:hover { color: #dfdfdf; }

最佳答案

您需要做的是设置翻转图像。一种用于正常的“未悬停”状态,另一种用于“悬停”并将相关类应用于您的导航链接。

...
<li><a href="#" class="home">Home</a></li>
<li><a href="#" class="about">About Us</a></li>
...

然后您可以使用 CSS 在元素悬停时将图像显示为背景图像:

<li><a href="#" class="home">Home</a></li>

nav ul li.home:hover {
background: url(../images/home-hover.jpg);
display: block;  /* apply this to give the element the dimensions of your image*/
width: 69px; /*width of your nav image*/
height: 25px; /*height of your nav image*/
}

这只是一个快速入门示例,但您需要为每个元素进行设置。

此外,您可能想查看 CSS Sprites

关于jquery - 使用 CSS 导航翻转并应用 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3876383/

相关文章:

android - 如何在导航控件 fragment 中关闭导航 DrawerLayout onBackPressed

javascript - 附加到 div 时滚动()事件未触发

dom - 修复了具有单个 DOM 元素的响应式顶部导航/关闭 Canvas 导航

php - 使用 AJAX 加载图像文件?

javascript - Cakephp 3.0 自动完成 jquery ui

css - 尝试创建网格/列短代码

html - 菜单项在 Chrome/Safari (Mac) 上中断,但在 Firefox 和 Chrome for Win 上不中断

html - 导航栏大小保持相对于内容

javascript - 使用 ajax 在 IFRAME 中加载页面

JQuery iframe内容跨域