css3网页制作实例:仿Apple.com的导航栏

http://www.itjxue.com  2015-08-05 23:40  来源:未知  点击次数: 

apple的官网有个相当不错的头部导航,今天我们运用css3的知识,不借助一张图片,来实现类似的效果。

下载源文件:http://www.itjxue.com/files/soft/1_121211104404.zip

1.会用到的css3知识

  • text-shadow :文字阴影
  • border-radius:圆角
  • box-shadow:容器阴影
  • box-shadow: inset :当增加inset后,表示使用内阴影
  • gradient :渐变,渐变的代码还是很多的,幸运的是网上有自动生成渐变的工具,请看CSS3 Gradient Generator
  • keyframes:这个属性就比较有意思,估计用的人很少,用于配合css3动画,理解为动画模块或一组css3动画设置。只有 WebKit 内核的浏览器支持这一特性,经过明河验证firefox4也不支持。

2.上一坨代码…

2.1导航容器样式
  1. /* 导航 */
  2. #appleNav {
  3. margin: 40px 0;
  4. list-style: none;
  5. /* Apple使用Lucida字体 */
  6. font-family: "Lucida Sans Unicode", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
  7. letter-spacing: -0.5px;
  8. font-size: 13px;
  9. /* 文字阴影 */
  10. text-shadow: 0 -1px 3px #202020;
  11. width: 873px;
  12. height: 34px;
  13. /*圆角*/
  14. -moz-border-radius: 4px;
  15. -webkit-border-radius: 4px;
  16. border-radius: 4px;
  17. /*阴影*/
  18. -moz-box-shadow: 0 3px 3px #cecece;
  19. -webkit-box-shadow: 0 3px 3px #cecece;
  20. box-shadow: 0 3px 4px #8b8b8b;
  21. }
2.2导航子元素样式
  1. #appleNav li {
  2. display: block;
  3. float: left;
  4. border-right: 1px solid #5d5d5d;
  5. border-left: 1px solid #929292;
  6. width: 105px;
  7. height: 34px;
  8. border-bottom: 1px solid #575757;
  9. border-top: 1px solid #797979;
  10. /*渐变背景,关于css3渐变效果制作请看http://gradients.glrzad.com/ */
  11. background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, #787878), color-stop(0.5, #5E5E5E), color-stop(0.51, #707070), color-stop(1, #838383));
  12. background-image: -moz-linear-gradient(center bottom, #787878 0%, #5E5E5E 50%, #707070 51%, #838383 100%);
  13. background-color: #5f5f5f;
  14. }
  15. /*鼠标滑过菜单元素后*/
  16. #appleNav li:hover {
  17. background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, #3F3F3F), color-stop(0.5, #383838), color-stop(0.51, #434343), color-stop(1, #555555));
  18. background-image: -moz-linear-gradient(center bottom, #3F3F3F 0%, #383838 50%, #434343 51%, #555555 100%);
  19. background-color: #383838;
  20. /*增加内阴影效果 */
  21. -moz-box-shadow: inset 0 0 5px 5px #535353;
  22. -webkit-box-shadow: inset 0 0 5px 5px #535353;
  23. box-shadow: inset 0 0 5px 5px #535353;
  24. }
  25. /*鼠标按下菜单元素后*/
  26. #appleNav li:active {
  27. background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, #3F3F3F), color-stop(0.5, #383838), color-stop(0.51, #434343), color-stop(1, #555555));
  28. background-image: -moz-linear-gradient(center bottom, #3F3F3F 0%, #383838 50%, #434343 51%, #555555 100%);
  29. background-color: #383838;
  30. -moz-box-shadow: inset 0 1px 2px 2px #000;
  31. -webkit-box-shadow: inset 0 1px 2px 2px #000;
  32. box-shadow: inset 0 1px 2px 2px #000;
  33. }

留意内阴影部分的处理。

2.3容器向下滑动的动画效果
  1. /*Webkit内核的浏览器增加动画效果 */
  2. @-webkit-keyframes showMenu {
  3. from { opacity: 0; top:-20px; }
  4. to { opacity: 1; }
  5. }
  6. #appleNav {
  7. -webkit-animation: showMenu 1s;
  8. position: relative;
  9. }

(责任编辑:IT教学网)

更多

推荐HTML/Xhtml文章