首页
网页制作
网络编程
脚本专栏
数据库
网站运营
网络安全
平面设计
CMS教程
搜索
建站极客
网页制作
CSS
正文
纯css实现的六边形(蜂窝)导航效果(支持hover/兼容浏览器)
所属分类:
网页制作
/
CSS
阅读数: 1157
收藏 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>
提示:您可以先修改部分代码再运行
更多精彩内容
其他人还在看
CSS入门教程:计算CSS盒模型宽和高
出处:当我们布局一个网页的时候,经常会遇到这样的一种情况,那就是最终网页成型的宽度或是高度会超出我们预先的计算,其实就就是所谓的CSS的盒模型造成的。 #test{margin:10px;padding:10px;width:100px;height:100px;}
评论 0
收藏 0
赞 0
分享
在IE流览器中正确显示PNG透明图片
png图片有很好的品质。阴影效果也不会有杂边,很流畅。如果插入网页的话可以给网站内容增色不少!更重要的是在不增加图片容量大小的情况下提高了页面的图片的质量。对于有复杂背景,如:在有颜色过度背景上插入不规则边框的图片带来极大很便利! 但目前IE中对于插入
评论 0
收藏 0
赞 0
分享
CSS教程:DIV底部放置文字
css对文字的布局上没有靠容器底部对齐的参数,目前使用的一个不错的方法也比较好.就是用position属性来解决,看下面的代码,用position的相对和绝对定位功能也轻松的实现了,文字靠近div低部对齐,并且靠近的距离还可以精确到像素,自己可以调节,是不是很不错呢?
评论 0
收藏 0
赞 0
分享
如何用CSS让文字居于div的底部
这个问题是别人提出的,因为css对文字的布局上没有靠容器底部对齐的参数,(或许有但是我没有发现)不过目前我使用的一个不错的方法也比较好.就是用position属性来解决,看下面的代码,我用position的相对和绝对定位功能也轻松的实现了,文字靠近div低部对齐,并且靠近
评论 0
收藏 0
赞 0
分享
从A页面连接到B页面后并直接把B页面的隐藏层显示
这个效果实现的是,在B页面里有两个层,一个显示层,我们暂定名c层,一个是隐藏层,我们暂定名d层,单独进B页面的时候,c层显示,d层隐藏,然而从A页面连接到B页面的时候,则是让d层显示,c层隐藏,我觉得这个效果对网页设计者以后会有很大帮助,现在把代码发出来,
评论 0
收藏 0
赞 0
分享
CSS样式表定义标签li前面样式
定义LI前面的小点样式 view plaincopy to clipboardprint? 语法: list-style-type : disc | circle | square | decimal | lower-roman | upper-roman | lowe
评论 0
收藏 0
赞 0
分享
符合标准的div css制作的弹出菜单
本文介绍了五款符合标准的div css制作的弹出菜单,而且不含有js的. NO.1最基本的:二级dropdown弹出菜单 <!DOCTYPE html PUB
评论 0
收藏 0
赞 0
分享
CSS实现在文章每段后面加入带连接的隐藏文字
代码主要理解3个参数:createElement、createTextNode、appendChild。这3个js参数分别是创建元素、创建字符、追加节点。代码原理:循环页面段落标签<p>,创建连接元素<a>,创建要显示的连接字符,用SetAttribute
评论 0
收藏 0
赞 0
分享
CSS:浏览器特定选择器介绍
当你想在一个浏览器里改变样式而不像在其他浏览器中改变时,这些选择器很有用。 IE6以下 *html{} IE 7 以下 *:first-child html {} * html {} 只对IE 7 *:first-child html {} 只对IE 7
评论 0
收藏 0
赞 0
分享
WEB标准学习,认识两种网页声明的含义
即网页标准推出来以后,我们时常会看到两种不同的网页的声明,一个是Dhtml,一个是Xhtml。如下所示: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "ht
评论 0
收藏 0
赞 0
分享
查看更多
网络赚钱
更多
巴西世界杯复盘:七大移动营销案例图文解析
如何适当提高垃圾站Google
第三次零售革命 - 智慧零售
网站如何靠SEO盈利?先把网站包装成专卖店吧
未来5大网络销售模式选哪种好?
Papi酱首次直播的八大平台是哪些 打赏90万服不服
站长故事
更多
写给所有站长:其实没必要参加SEO培训
从月薪3500到身价3千万
我是怎么赚到人生的第一个百万的
求伯君:如果时光倒流我不会选择创业
做好网站维护 持续吸引用户浏览
我对互联网VC的10点看法 知己知彼百战不殆