图片/图形

CSS3导航菜单背景模糊特效

阿里云


这是一款使用 css3 transition 属性制作的导航菜单背景模糊特效插件。这款插件共集合了 7 种不同的导航菜单背景模糊效果。其效果是当鼠标滑过菜单时,当前菜单项清晰显示,其余项变得模糊。

HTML 结构

7 个 demo 使用了相同的 html 结构:

也想出现在这里?联系我们
创客主机
  1. <ul class="bmenu">
  2.     <li><a href="#">About</a></li>
  3.     <li><a href="#">Illustrations</a></li>
  4.     <li><a href="#">Photography</a></li>
  5.     <li><a href="#">Web Design</a></li>
  6.     <li><a href="#">Personal Projects</a></li>
  7.     <li><a href="#">Contact</a></li>
  8. </ul>

CSS 样式

通用 css 部分如下:

  1. .bmenu{
  2.     padding: 0px;
  3.     margin: 0 0 10px 0;
  4.     position: relative;
  5. }
  6. .bmenu li{
  7.     font-size: 50px;
  8.     display: block;
  9. }


在第一个 demo 中,我们希望菜单项在开始时是模糊的。为了做到这一点,我们给超链接元素透明的颜色和白色的文字阴影。并为所有的属性添加 transitions。

  1. .bmenu li a{
  2.     color: transparent;
  3.     display: block;
  4.     text-transform: uppercase;
  5.     text-shadow: 0px 0px 5px #fff;
  6.     letter-spacing: 1px;
  7.     -webkit-transition: all 0.3s ease-in-out;
  8.     -moz-transition: all 0.3s ease-in-out;
  9.     -o-transition: all 0.3s ease-in-out;
  10.     -ms-transition: all 0.3s ease-in-out;
  11.     transition: all 0.3s ease-in-out;
  12. }

当鼠标滑过某个菜单项时,我们希望它变得清晰,而其他项更模糊。在这里不能使用兄弟选择器来获取“其它”所有的菜单项,只能获取当前鼠标滑过菜单项后面的菜单项。所以在这里要使用一点小技巧,因为所有的菜单项都被设置为块级元素,因此可以简单的在鼠标 Hover 的时候将整个菜单都变得模糊,然后将当前项变清新即可。

  1. .bmenu:hover li a{
  2.     text-shadow: 0px 0px 5px #0d1a3a;
  3. }
  4. .bmenu li a:hover{
  5.     color: #fff;
  6.     text-shadow: 0px 0px 1px #fff;
  7.     padding-left: 10px;
  8. }


在第二个 demo 中,鼠标 hover 时菜单项有些倾斜效果。我们将使用 2D transforms 来完成倾斜效果。倾斜的角度将被设置为 x 轴方向的-12 度。超链接的背景色使用 rgba 设置为半透明。还为文字添加一个稍微透明的文字阴影。

  1. .bmenu li a{
  2.     display: block;
  3.     text-transform: uppercase;
  4.     text-shadow: 1px 1px 2px rgba(89,22,20,0.3);
  5.     color: #581514;
  6.     padding: 5px 20px;
  7.     margin: 2px;
  8.     background: rgba(255,255,255,0.2);
  9.     letter-spacing: 1px;
  10.     -webkit-transform: skew(-12deg);
  11.     -moz-transform: skew(-12deg);
  12.     -o-transform: skew(-12deg);
  13.     -ms-transform: skew(-12deg);
  14.     transform: skew(-12deg);
  15.     -webkit-transition: all 0.4s ease-in-out;
  16.     -moz-transition: all 0.4s ease-in-out;
  17.     -o-transition: all 0.4s ease-in-out;
  18.     -ms-transition: all 0.4s ease-in-out;
  19.     transition: all 0.4s ease-in-out;
  20. }

鼠标滑过菜单项时,设置倾斜角度为 0,并通过设置半透明背景使菜单变得模糊,当前 hover 的菜单项没有背景:

  1. .bmenu:hover li a{
  2.     color: transparent;
  3.     text-shadow: 0px 0px 10px #fff;
  4.     background: rgba(88,22,22,0.2);
  5.     -webkit-transform: skew(0deg);
  6.     -moz-transform: skew(0deg);
  7.     -o-transform: skew(0deg);
  8.     -ms-transform: skew(0deg);
  9.     transform: skew(0deg);
  10. }
  11. .bmenu li a:hover{
  12.     background: transparent;
  13.     text-shadow: 1px 1px 10px rgba(89,22,20,0.6);
  14.     color: #581514;
  15. }


第三个 demo 中文字大小做了些变化。开始时是菜单文字缩小、变模糊。我们将使用一个相当缓慢的线性转换:

  1. .bmenu li a{
  2.     white-space: nowrap;
  3.     color: transparent;
  4.     display: block;
  5.     text-transform: uppercase;
  6.     text-align: center;
  7.     text-shadow: 0px 0px 6px #fff;
  8.     letter-spacing: 1px;
  9.     -moz-transform: scale(0.5); 
  10.     -ms-transform: scale(0.5); 
  11.     -o-transform: scale(0.5); 
  12.     -webkit-transform: scale(0.5); 
  13.     transform: scale(0.5); 
  14.     -webkit-transition: all 0.6s linear;
  15.     -moz-transition: all 0.6s linear;
  16.     -o-transition: all 0.6s linear;
  17.     -ms-transition: all 0.6s linear;
  18.     transition: all 0.6s linear;
  19. }

鼠标 hover 时其它所有项更模糊,当前项变清晰并放大:

  1. .bmenu:hover li a{
  2.     text-shadow: 0px 0px 15px #fff;
  3. }
  4. .bmenu li a:hover{
  5.     text-shadow: 0px 0px 1px #fff;
  6.     -moz-transform: scale(1); 
  7.     -ms-transform: scale(1); 
  8.     -o-transform: scale(1); 
  9.     -webkit-transform: scale(1); 
  10.     transform: scale(1); 
  11. }


在这个 demo 中给超链接元素半透明的黑色背景和橙色的文字颜色。这个 demo 中将使用到 timing transition。

  1. .bmenu li a{
  2.     display: block;
  3.     text-transform: uppercase;
  4.     text-shadow: 0px 0px 2px #eeb213;
  5.     color: #eeb213;
  6.     padding: 5px 20px;
  7.     margin: 2px;
  8.     background: rgba(0,0,0,0.7);
  9.     letter-spacing: 1px;
  10.     -webkit-transition: all 0.2s linear;
  11.     -moz-transition: all 0.2s linear;
  12.     -o-transition: all 0.2s linear;
  13.     -ms-transition: all 0.2s linear;
  14.     transition: all 0.2s linear;
  15. }

当鼠标 hover 的时候,菜单项模糊,它们的背景色更加透明。当前 hover 项将不透明:我们通过指定一些时间延时来制作缩略图依次出现的效果:

  1. .bmenu:hover li a{
  2.     text-shadow: 0px 0px 10px #eeb213;
  3.     color: transparent;
  4.     background: rgba(0,0,0,0.2);
  5. }
  6. .bmenu li a:hover{
  7.     background: rgba(0,0,0,1.0);
  8.     text-shadow: 0px 0px 1px #eeb213;
  9. }


第 5 个 demo 使用白色的文字阴影和文本颜色,我们只轻微的模糊菜单项元素:

  1. .bmenu li a{
  2.     color: transparent;
  3.     display: block;
  4.     text-transform: uppercase;
  5.     text-shadow: 0px 0px 4px #fff;
  6.     letter-spacing: 1px;
  7.     -webkit-transition: all 0.2s ease-in-out;
  8.     -moz-transition: all 0.2s ease-in-out;
  9.     -o-transition: all 0.2s ease-in-out;
  10.     -ms-transition: all 0.2s ease-in-out;
  11.     transition: all 0.2s ease-in-out;
  12. }

鼠标滑过时将使菜单项模糊一些并稍稍移动一点距离:

  1. .bmenu:hover li a{
  2.     text-shadow: 0px 0px 6px #fff;
  3. }
  4. .bmenu li a:hover{
  5.     color: #fff;
  6.     text-shadow: 0px 0px 1px #fff;
  7.     padding-left: 10px;
  8. }


第 6 个 demo 设置背景色为半透明白色:

  1. .bmenu li a{
  2.     white-space: nowrap;
  3.     display: block;
  4.     text-transform: uppercase;
  5.     text-shadow: 1px 1px 2px rgba(71,80,23,0.3);
  6.     color: #fff;
  7.     padding: 5px 20px;
  8.     margin: 2px;
  9.     background: rgba(255,255,255,0.2);
  10.     letter-spacing: 1px;
  11.     -webkit-transition: all 0.4s ease-in-out;
  12.     -moz-transition: all 0.4s ease-in-out;
  13.     -o-transition: all 0.4s ease-in-out;
  14.     -ms-transition: all 0.4s ease-in-out;
  15.     transition: all 0.4s ease-in-out;
  16. }

使用 first-child 和 last-child 选择器为第一个和最后一个元素添加圆角:

  1. .bmenu li:first-child a{
  2.     -webkit-border-radius: 15px 15px 0px 0px;
  3.     -moz-border-radius: 15px 15px 0px 0px;
  4.     border-radius: 15px 15px 0px 0px;
  5. }
  6. .bmenu li:last-child a{
  7.     -webkit-border-radius: 0px 0px 15px 15px;
  8.     -moz-border-radius: 0px 0px 15px 15px;
  9.     border-radius: 0px 0px 15px 15px;
  10. }

鼠标 hover 时其它元素模糊,当前元素变清晰,并且背景色变透明:

  1. .bmenu:hover li a{
  2.     text-shadow: 0px 0px 10px #fff;
  3.     color: transparent;
  4. }
  5. .bmenu li a:hover{
  6.     background: transparent;
  7.     text-shadow: 1px 1px 10px rgba(71,80,23,0.6);
  8.     color: #c4d85a;
  9. }


最后一个 demo 通过设置 border radius 为宽高的一半将菜单变为圆形。

  1. .bmenu{
  2.     padding: 50px 0px;
  3.     margin: 0 auto;
  4.     position: relative;
  5.     background: rgba(0,0,0,0.7);
  6.     width: 500px;
  7.     height: 400px;
  8.     -webkit-border-radius: 250px;
  9.     -moz-border-radius: 250px;
  10.     border-radius: 250px;
  11.     -webkit-transition: background-color 0.5s ease-in-out;
  12.     -moz-transition: background-color 0.5s ease-in-out;
  13.     -o-transition: background-color 0.5s ease-in-out;
  14.     -ms-transition: background-color 0.5s ease-in-out;
  15.     transition: background-color 0.5s ease-in-out;
  16. }

这里添加 transitions 是为了在鼠标滑过时背景有动画效果,通过 rgba 将背景变得更加透明:

  1. .bmenu:hover{
  2.     background: rgba(0,0,0,0.2);
  3. }

调整一下菜单项文字大小和行高:

  1. .bmenu li{
  2.     font-size: 40px;
  3.     display: block;
  4.     line-height: 66px;
  5. }

菜单项元素将被缩小和模糊:

  1. .bmenu li a{
  2.     white-space: nowrap;
  3.     color: transparent;
  4.     display: block;
  5.     text-align: center;
  6.     text-transform: uppercase;
  7.     text-shadow: 0px 0px 3px #fff;
  8.     letter-spacing: 1px;
  9.     -moz-transform: scale(0.8); 
  10.     -ms-transform: scale(0.8); 
  11.     -o-transform: scale(0.8); 
  12.     -webkit-transform: scale(0.8); 
  13.     transform: scale(0.8);
  14.     -webkit-transition: all 0.4s linear;
  15.     -moz-transition: all 0.4s linear;
  16.     -o-transition: all 0.4s linear;
  17.     -ms-transition: all 0.4s linear;
  18.     transition: all 0.4s linear;
  19. }

鼠标滑过时将使元素更加模糊,给当前 hover 元素一个好看的背景色,并使它的文字大小恢复到原来的尺寸:

  1. .bmenu:hover li a{
  2.     text-shadow: 0px 0px 10px #fff;
  3. }
  4. .bmenu li a:hover{
  5.     text-shadow: none;
  6.     color: #fff;
  7.     background: rgba(129,6,29,0.8);
  8.     -moz-transform: scale(1); 
  9.     -ms-transform: scale(1); 
  10.     -o-transform: scale(1); 
  11.     -webkit-transform: scale(1); 
  12.     transform: scale(1); 
  13. }

注意:某些 IE 浏览器不支持文字阴影效果,如果你实在需要,可以参考下面的文档:

CSS Blurred Text-Shadow in IE — Part I

IE Visual Filters and Transitions Reference: Static Filters

CSS3 导航菜单背景模糊特效

已有 477 人购买
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!