首页
网页制作
网络编程
脚本专栏
数据库
网站运营
网络安全
平面设计
CMS教程
搜索
建站极客
网页制作
CSS
正文
纯css实现的六边形(蜂窝)导航效果(支持hover/兼容浏览器)
所属分类:
网页制作
/
CSS
阅读数: 1163
收藏 0
赞 0
分享
博客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;visibility: hidden;overflow:hidden;} .post{width:120px;height:80px;display:inline-block;background:#0099ff;float:left;border-right:1px dotted #fff;border-left:1px dotted #fff;margin-top:100px;position:relative;overflow:visible;margin-top:52px;-webkit-transition:all .3s linear;-moz-transition:all .3s linear;} .post:before{content:"<em></em>";width:0px;height:0px;display:inline-block;border-left: 60px dotted transparent; border-right: 60px dotted transparent; border-bottom: 50px solid #0099ff;font-size:0;position:absolute;top:-50px;left:0px;} .post:after{content:"<em></em>";width:0px;height:0px;display:inline-block;border-left: 60px dotted transparent; border-right: 60px dotted transparent; border-top: 50px solid #0099ff;font-size:0;position:absolute;bottom:-50px;left:0px;} </style> </head> <body> <div id="wrap"> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> <div class='post'> </div> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script> <script> (function($){ $.fn.sixBorder = function(options){ var defaults={ post:'post' } var options=$.extend(defaults,options); var wrapWidth=$(this)[0].offsetWidth,postWidth=$("."+options.post)[0].offsetWidth,lineNum=Math.floor(wrapWidth/postWidth),lineLimit=Math.floor((wrapWidth-61)/postWidth); $("."+options.post).each(function(index){ var _this = $(this); _this.css({'margin-left':'0px'}); if(lineLimit == lineNum){ var numPer=index%lineNum; if(numPer == 0){ var linePer=Math.floor(index/lineNum)%2; if(linePer == 1){ _this.css({'margin-left':'61px'}); } } }else{ var numPer=index%(lineLimit+lineNum); if(numPer == 0){ _this.css({'margin-left':'61px'}); } }; }); } })(jQuery); $("#wrap").sixBorder(); $(window).resize(function(){ $("#wrap").sixBorder(); }); </script> </body> </html>
提示:您可以先修改部分代码再运行
更多精彩内容
其他人还在看
Opera中国的WEB标准课程
网页制作Webjx文章简介:在这篇文章里,我要向大家介绍我和其他很多人花费数月时间开发的一个课程——Web标准课程,该课程旨在向大家提供Web设计和开发的坚实基础,无论读者是谁,此教程完全免费、可访问,并且不需要预备知识。当然,我主要还
评论 0
收藏 0
赞 0
分享
CSS样式表渐进增强的基本概念
网页制作Webjx文章简介:如果你挠着头想弄清楚优雅降级和渐进增强的区别,我告诉你,这是视角问题。优雅降级和渐进增强都考虑网站在各种设备的各种浏览器上如何良好运转。两者区别的关键在于它们各自关注的焦点,以及这种关注对工作流程的影响
评论 0
收藏 0
赞 0
分享
简单介绍Web Developer插件制作网页
网页制作Webjx文章简介:Firefox浏览器是一个良好支持W3C标准的开放源代码的浏览器,拥有Linux/Windows/Mac版本。因为Firefox浏览器良好支持W3C标准,所以使用Firefox来调试网页是非常好的。 Firefox浏览器是
评论 0
收藏 0
赞 0
分享
CSS布局带来的巨大影响:CSS display属性值
网页制作Webjx文章简介:网页元素应用上那些与表格相关的display属性值后,能够模仿出与表格相同的特性。我将会在该文中给大家演示这种方法给CSS布局带来的巨大影响。 应原书编辑要求,先在文章顶部给出链接:《Everything You
评论 0
收藏 0
赞 0
分享
用div css模拟表格对角线
这只是探讨一种CSS模拟表格对角线的用法,实际在工作中可能觉得这样做有点小题大作,这不是本主题讨论的重点。如果对此深以为然的朋友,请一笑过之 首先声明: 这只是探讨一种CSS模拟表格对角线的
评论 0
收藏 0
赞 0
分享
IE Firefox在css中的差别 (部分)
1、单位问题 问题:任何距离的数值ie可以不加单位,ff必须要求写单位(0除外) 解决:写全单位如padding:0px; 2、水平居中 问题:div里的内容,ie默认为center,而ff默认left 解决:mairgin:0px auto; 3、高度问题
评论 0
收藏 0
赞 0
分享
不用js可以实现信息提示效果
[code] <style> body { font:verdena; font-size:14px; color:#000 } h1{ font:verdena; font-size:22px; color:#000 } h2{ font:verdena;
评论 0
收藏 0
赞 0
分享
CSS解决未知高度的垂直水平居中自适应问题
今天有人问起,晚上试着写出来,供参考; 以下代码兼容主流浏览器IE6、IE7、Firefox、Opera。 从最简单的开始………… 一、如何让一个DIV水平居中? 这个简单不作过多说明! [code] <st
评论 0
收藏 0
赞 0
分享
CSS cursor 属性 -- 鼠标指针样式效果
取值: [ [<uri> ,]* [ auto | crosshair | default | pointer | move | e-resize | ne-resize | nw-resize | n-resize | se-resize | sw-resize |
评论 0
收藏 0
赞 0
分享
css 简单区别ie6,ie7,firefox的写法
同一样式里可以这样 [code] margin:17px; FF +margin:17px; IE6 IE7 _margin:17px; IE6 [/code] 按这个顺序,刚好区分开三个浏览器
评论 0
收藏 0
赞 0
分享
查看更多
网络赚钱
更多
屌丝伪装高富帅 用女友朋友圈低价卖iPhone 6 卷走180万
百度联盟点击率低的原因
做什么样的网站能赚钱?
短视频如何赚钱?短视频自媒体实操经验分享(真实)
六一儿童节微营销秘籍 互动吸粉6大招
为什么做网站不赚钱?做网站不赚钱的三大原因
站长故事
更多
某个人站长怎么用交友网站年赚80万的
互联网屌丝合伙创业经验分享
一个大学生自述:我是如何把公司做死的
作为站长的你是否已有危机感:你被盯上了
一成不变的站长到底还能活多久?
我对互联网VC的10点看法 知己知彼百战不殆