css3绘制六边形

六边形思路:使用CSS3绘制六边形主要使用伪类:before和:after在源元素之前和之后再绘制两个元素,并利用css3的边框样式,将这两个元素变成三角形放置在源元素的两端即可。

<h2>三角形在左右两侧</h2>
<!-- 第一种方法 不兼容低版本浏览器 -->
   <div class="hexagon1"></div>
   <!-- 第二种方法  兼容低版本浏览器 -->
   <div class="hexagon2">
        <div class="left"></div>
        <div class="right"></div>
   </div>

    <h2>三角形在上下两侧</h2>
    <div class="hexagon3"></div>
.hexagon1{
        width: 50px;
        height: 80px;
        background-color:#6c6 ;
        position: relative;
        margin:0 auto;
    }
    .hexagon1::before{
        width: 0;
        height: 0;
        content: ‘‘;
        position: absolute;
        top: 0;
        left:-20px;
        border-right: 20px solid #6c6;
        border-top:40px solid transparent;
        border-bottom:40px solid transparent;
    }
    .hexagon1::after{
        width: 0;
        height: 0;
        content: ‘‘;
        position: absolute;
        top: 0;
        right:-20px;
        border-left: 20px solid #6c6;
        border-top:40px solid transparent;
        border-bottom:40px solid transparent;
    }

    .hexagon2{
        width: 50px;
        height: 80px;
        background-color:orange ;
        position: relative;
        margin:0 auto;
    }
      .hexagon2 .left{
        width: 0;
        height: 0;
        position: absolute;
        left: -20px;
        top: 0;
        border-right: 20px solid orange;
        border-top: 40px solid transparent;
        border-bottom: 40px solid transparent;
      }
      .hexagon2 .right{
        width: 0;
        height: 0;
        position: absolute;
        right: -20px;
        top: 0;
        border-left: 20px solid orange;
        border-top: 40px solid transparent;
        border-bottom: 40px solid transparent;
      }

      /*三角形在上下侧*/
      .hexagon3{
        width: 80px;
        height: 40px;
        background-color: blue;
        margin:0 auto;
        position: relative;
      }
      .hexagon3::before{
        width: 0;
        height: 0;
        content: ‘‘;
        position: absolute;
        top: -20px;
        left: 0;
        border-bottom: 20px solid blue;
        border-left: 40px solid transparent;
        border-right: 40px solid transparent;
      }
      .hexagon3::after{
        width: 0;
        height: 0;
        content: ‘‘;
        position: absolute;
        bottom: -20px;
        left: 0;
        border-top: 20px solid blue;
        border-left: 40px solid transparent;
        border-right: 40px solid transparent;
      }

.sharp:before{
         content:""; 
         width:0px;
         border-bottom:80px solid transparent;
         border-top:80px solid transparent;
         border-right:40px solid #6c6;
         position:absolute;
         left:-40px;
         top:0px;
     }
     .sharp{
         min-width:100px;
         height:160px;
         background:#6c6;
         display: inline-block;
         position: absolute;
         line-height: 160px;
         color:#FFFFFF;
         font-size: 20px;
         text-align: center;
     }
     .sharp:after{
         content:"";  
         width:0px;
         border-bottom:80px solid transparent;
         border-top:80px solid transparent;
         border-left:40px solid #6c6;
         position:absolute;
         right:-40px;
         top:0px;
     }
        #sharpContainer{
            width:100%;
            height: 600px;
        }
        #sharpContainer .center{
            top:200px;
            left:300px;
        }
         #sharpContainer .top{
             top:20px;
             left:300px;
         }
         #sharpContainer .top-left{
             top:110px;
             left:140px;
         }
         #sharpContainer .top-right{
             top:110px;
             left:460px;
         }
         #sharpContainer .bottom{
             top:380px;
             left:300px;
         }
         #sharpContainer .bottom-left{
             top:290px;
             left:140px;
         }
         #sharpContainer .bottom-right{
             top:290px;
             left:460px;
         }
<div id="sharpContainer">
    <div class="sharp center"></div>
    <div class="sharp top"></div>
    <div class="sharp top-left"></div>
    <div class="sharp top-right"></div>
    <div class="sharp bottom"></div>
    <div class="sharp bottom-left"></div>
    <div class="sharp bottom-right"></div>
</div>

时间: 2024-08-05 11:12:30

css3绘制六边形的相关文章

css绘制六边形

CSS id选择器实现 正六边形 用css绘制六边形需要使用到三个容器,分别用于绘制六边形的三个部分,如下图所示: HTML代码: 1 <div id="box1"></div> 2 <div id="box2"></div> 3 <div id="box3"></div> CSS代码: #box1{width:0;border-left: 52px solid transp

CSS3 实现六边形Div图片展示效果

效果图: 实现原理: 这个效果的主要css样式有: 1.>transform: rotate(120deg); 图片旋转 2.>overflow:hidden;  超出隐藏 3.>visibility: hidden;  也是隐藏,与display:none;相似,但不同的是,它虽然隐藏了,但依然会在网页中占有位置 我们要用到3层div进行旋转来得到这个效果(ps:3层div的大小是一样的). 最外层div(boxF)旋转120度.第二层(boxS)旋转-60度,第三层(boxT)再旋转

用纯css3绘制的能自适应浏览器的哆啦a梦动画

最近在研究用css3绘制矢量图,于是就用纯css3绘制了能自适应浏览器宽度的哆啦a梦动画,兼容css3的浏览器都可以正常观看,下面只是网页截图: 废话不多说了,直接给代码. html 代码: <div class="dlam" title="用纯css3绘制的能自适应浏览器的哆啦a梦动画"> <div class="bozi"> <div class="lingdan"> <div c

CSS3绘制8种超炫的加载动画

CSS3绘制8种超炫的加载动画     逛前端开发网站的时候,偶尔发现一组非常炫酷的CSS3加载动画,遂迫不及待的做个Demo保存下来. 这些加载动画用到了CSS3的旋转transform属性,颜色透明度设置和伪元素操作等CSS技术.奇妙的组合,产生了意想不到的效果. 1.上下起伏波动的加载动画: #loader1, #loader1:before, #loader1:after { background: #f2fa08; -webkit-animation: load1 1s infinit

用纯CSS3绘制萌系漫画人物动态头像

大家已经见惯了用CSS3画的图标.LOGO.头像,这次台湾同学Rei给我们带来了用纯CSS3绘制的日本动漫<轻音少女>女主角秋山澪的动态头像.看到动图我震惊了!!!CSS3的强大再次霸气测漏! 示例中用到的主要CSS3特性如下: border-radius:绘制边框圆角. transform:主要是旋转(rotate)和偏斜(skew),用于绘制各种形状. animation:动画效果的实现,例如头发的飘动.眼睛的闪动. 只要掌握了这几个特性,你也能画出同样奇妙的CSS3动画,赶快试试吧!

CSS3绘制砖墙-没有用任何图片

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Typ

使用css绘制六边形

用css绘制六边形需要使用到三个容器,分别用于绘制六边形的三个部分,如下图所示: 接下来,就是代码了: CSS: <style>    #box1{width:0;border-left: 52px solid transparent;border-right: 52px solid transparent;border-bottom: 30px solid #6c6;    }    #box2{width: 104px;height: 60px;background-color: #6c6

CSS3绘制旋转的太极图案

1.效果布局主要用了用了3个DIV,配合:before.:after利用css3中的圆角(border-radius).阴影(box-shadow)完成. 2.动画效果CSS3中的@keyframes.animation <!doctype html> <html> <head> <meta charset="utf-8"> <title>CSS3绘制旋转的太极图案</title> <style> bo

css3绘制各种图形效果

如何使用CSS来制作图形,比如说圆形,半圆形,三角形等.今天我特意在网上查阅了一下,介绍这样的教程还是蛮多的,因此我也决定整理一份相关教程出来与大家一起分享. 很少会有人意识到,当浏览器绘制的border,会有一个角度的问题.我们就是得用这样的一个技巧来制作三角的效果.我们只需要保证一边的边框是有色,其他边框色为透明色,这样我们就很容易制作出三角形,然后改变其大小来实现不同的效果.我们一起来看一段代码: 1 2 3 4 5 6 7 .css-arrow-multicolor { border-c