• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com专业计算机教程网站
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • html/xhtml
  • html5
  • CSS
  • XML/XSLT
  • Dreamweaver教程
  • Frontpage教程
  • 心得技巧
  • bootstrap
  • vue
  • AngularJS
  • HBuilder教程
  • css3
  • 浏览器兼容
  • div/css
  • 网页编辑器
  • axure
您的位置:首页 > 网页设计 >CSS > 纯css实现的六边形(蜂窝)导航效果(支持hover/兼容浏览器)

纯css实现的六边形(蜂窝)导航效果(支持hover/兼容浏览器)

作者:佚名 字体:[增加 减小] 来源:互联网 时间:2017-08-06

本文主要包含蜂窝,六边形等相关知识,佚名 希望在学习及工作中可以帮助到您
博客foreach(everyday){久}不更新了,关于前端开发方面的东西最近关注也没有往常频繁了。百度大神依旧对我的网站不闻不顾,无奈。但是技术还是要提高,分享依旧要继续。顺应一句话,你收或者不收,我都在这里。只增不减,不悲不喜。 

 ok,废话免谈。在之前的文章中曾经写到过一篇“三角形变形记之纯css实现的分布导航条效果”,其中用到了边框实现三角形的效果。最近又折腾了一个六边形的蜂窝效果给大家蹂躏。主要用到了是两个绝对定位的三角形,一个在上面一个在下面。配合一个长方形拼接成了六边形。该效果兼容各大主流浏览器,支持hover效果,重要的是纯css实现的。不多说了,大家运行代码观看效果吧。


<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>六边形</title> <style> .wrap{margin:100px;width:303px;} .nav{width:100px;height:58px;background:#339933;display:inline-block;position:relative;line-height:58px;text-align:center;color:#ffffff;font-size:14px;text-decoration:none;float:left;margin-top:31px;margin-right:1px;} .nav s{width:0;height:0;display:block;overflow:hidden;position:absolute;border-left:50px dotted transparent;border-right:50px dotted transparent;border-bottom:30px solid #339933;left:0px;top:-30px;} .nav b{width:0;height:0;display:block;overflow:hidden;position:absolute;border-left:50px dotted transparent;border-right:50px dotted transparent;border-top:30px solid #339933;bottom:-30px;left:0px;} .a0{margin-left:100px;} .a1{margin-left:50px;} .nav:hover{background:#8CBF26;color:#333333;} .nav:hover s{border-bottom-color:#8CBF26;} .nav:hover b{border-top-color:#8CBF26;} </style> </head> <body> <div class="wrap"> <a class="nav a0" target="_blank" href="#"><s></s>广播<b></b></a> <a class="nav a1" target="_blank" href="#"><s></s>广播<b></b></a> <a class="nav a2" target="_blank" href="#"><s></s>广播<b></b></a> <a class="nav a3" target="_blank" href="#"><s></s>广播<b></b></a> <a class="nav a4" target="_blank" href="#"><s></s>广播<b></b></a> <a class="nav a5" target="_blank" href="#"><s></s>广播<b></b></a> </div> </body> </html>
提示:您可以先修改部分代码再运行
具体实现的原理部分就不多说了,大家下载下来代码稍加研究就明白了。利用这个效果可以做多种多样的效果。关键是看每个人的思维发散空间,我比较笨,做不来特别有想法的东西,仅此提供方法给那些有想法的developer。另外下面说下一个关于边框实现三角形在ie6的兼容效果。

在之前的三角形变形记之纯css实现的分布导航条效果文章中写了比较详细的边框实现三角形的方法,但是在针对ie6的方法上不是特别的完美。现在发出最新的兼容ie6的方法,就是非显示的边框border-style设置为dotted,需要显示的边框border-style设置为solid;

提示:请在ie6下对比查看,如有bug欢迎反馈


<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>ie6下实现三角形</title> </head> <body style="background:#ececec;"> <div style="width: 0px; height: 0px; display: inline-block; margin-left: 20px; border: 40px solid transparent; border-bottom-color: #f70; font-size: 0; float: left;"> </div> <div style="width: 0px; height: 0px; display: inline-block; margin-left: 20px; border: 40px solid transparent;_border-color: snow; _filter: chroma(color=snow); border-bottom-color: #f70; font-size: 0; float: left;"> </div> <div style="width: 0px; height: 0px; display: inline-block; margin-left: 20px; border: 40px dotted transparent; border-bottom:40px solid #f70; font-size: 0; float: left;"> </div> </body> </html>
提示:您可以先修改部分代码再运行
纯css实现六边形的高级进阶

实现了六边形难免想要整出点幺蛾子来。下面我给该六边形加了一个背景图,做背景平铺到六边形的后面。样式可以简单实现了,但是仍旧存在诸多的不足,1是ie的兼容问题,然后是如果存在多个的情况下,不能实现蜂窝的效果。哪位高手如能完美实现,还请告知。下面看我实现代码:


<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>六边形</title> <style> .wrap{margin:100px;width:303px;} .nav{width:100px;height:58px;background:#339933;display:inline-block;position:relative;line-height:58px;text-align:center;color:#ffffff;font-size:14px;text-decoration:none;float:left;margin-top:31px;margin-right:1px;background:url(http://www.niumowang.org/wp-content/uploads//2012/08/b.png) center;} .nav s{width:0;height:0;display:block;overflow:hidden;position:absolute;border-left:50px dotted #fff;border-right:50px dotted #fff;border-bottom:30px solid transparent;left:0px;top:-30px;background:url(http://www.niumowang.org/wp-content/uploads//2012/08/b.png) top center;} .nav b{width:0;height:0;display:block;overflow:hidden;position:absolute;border-left:50px dotted #fff;border-right:50px dotted #fff;border-top:30px solid transparent;bottom:-30px;left:0px;background:url(http://www.niumowang.org/wp-content/uploads//2012/08/b.png) bottom center;} </style> </head> <body> <div class="wrap"> <a class="nav a0" target="_blank" href="#"><s></s>!!妹纸!!<b></b></a> </div> </body> </html>
提示:您可以先修改部分代码再运行
实现原理上比较单纯,在之前的蜂窝效果上加个背景图。设置显示的边框的背景颜色是透明。需要注意的是采用的图片的高度等于整个六边形的高度(比如我这张图片的高度=长方形高度58+上面三角形border-bottom宽度30+下面三角形border-top宽度30=118px),并设置上下部分的背景为同一个图片,上面的用background-position定位到top center;下面的图片定位到 bottom center;这样的话整个图片刚好被遮住形成六边形背景的效果。不过仍旧是有不足的。欢迎大家提出更好的方法。

蜂窝来袭,Are you ready ?
最后采用了css伪类元素,并结合jquery做了一个真正的蜂窝效果。当然ie6是不在兼容范围内的。感兴趣的朋友自行折腾吧。代码写的比较匆忙,也比较粗糙。大家看后乐呵乐呵就罢了。不过还是那句话,有问题欢迎留言讨论。


<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>蜂窝来袭,Are you ready ?</title> <style> html,body{margin:0;padding:0;width:100%;} #wrap{margin:0;padding:0;width:100%;} #wrap:after{content:"";display:block;height:0;clear:both;vis

您可能想查找下面的文章:

  • 纯css实现的六边形(蜂窝)导航效果(支持hover/兼容浏览器)

相关文章

  • 2017-08-06div中英文无法自动换行的解决办法
  • 2017-08-06完美实现文字置于图片之上且背景半透明
  • 2017-08-06用CSS手写导航条没有任何图片附效果图
  • 2017-08-06css之clearfix的用法深入理解(必看篇)
  • 2017-08-06借助CSS定位来实现把一个DIV放到另一个div右下角
  • 2017-08-06空格 在ie与在firefox下长度不一样问题
  • 2017-08-06CSS3 transform的skew属性值图文详解
  • 2017-08-06通过CSS让TD自动换行
  • 2017-08-06CSS布局实例代码 两列布局实例
  • 2017-08-06css margin-left在IE6下的问题的解决方法

文章分类

  • html/xhtml
  • html5
  • CSS
  • XML/XSLT
  • Dreamweaver教程
  • Frontpage教程
  • 心得技巧
  • bootstrap
  • vue
  • AngularJS
  • HBuilder教程
  • css3
  • 浏览器兼容
  • div/css
  • 网页编辑器
  • axure

最近更新的内容

    • 设置一个层在浏览器中同时左右居中上下居中水平垂直居中
    • CSS布局中如何组织样式表以便于简化、维护
    • DIV多层嵌套margin-top的BUG问题
    • 详解CSS中的选择器优先级及样式层叠问题解决
    • 一款利用css3的鼠标经过动画显示详情特效的实例教程
    • -moz-user-select与onselectstart 禁止选择文字的方法
    • 纯css 圆角实现代码
    • 浅谈CSS响应式图片运用中的srcset属性
    • div+css最小高度的实现代码(兼容ie6/ie7/ie8/firefox)
    • css按钮自适应实现原理及代码

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有