zoukankan      html  css  js  c++  java
  • 使用CSS样式,制作六边形


     



              在制作网上中,经常会遇到绘制其它不规则的图形,如六边形,八边形这类的,在复杂的图形,也是由我们的基本图形组成了,如上面的六边形,就是由两个三角形,一个矩形组成。 
       先看看,如何绘制三角形 ,与四边形。         三角形: 
                          <div class="triangle"></div> 
                          .triangle{ 
                                0px;   
                              height: 0px;   
                             border- 80px; 
                              border-color:transparent transparent green; 
                              border-style: solid; 
                          } 
             注: 将宽与高设置为0,设置边框的宽度,及样式的样式,最后将上,左,右边的边框,设置成透明色,这样我们就可以得到想到的三角形。 
            如图:   

                四边形: 
                          与三角形设置类似,不同的是,需要设置div的宽度,我们需要一个小的四边形与一个大的四边形,改变宽度的大小即可: 
                            <div class="fourangle"></div> 
                            <div class="fourangle2"></div>           
                             .fourangle{ 
                                         70px;   
                                       height: 0px;   
                                       border- 80px; 
                                        border-color:transparent transparent green; 
                                        border-style: solid; 
                                } 
                                .fourangle2{ 
                                         100px;   
                                       height: 0px;   
                                       border- 80px; 
                                        border-color:transparent transparent green; 
                                        border-style: solid; 
                                } 
                   效果如图: 
                         




         完整六边形代码如下: 
    <!DOCTYPE html> 
    <html> 
    <head lang="en"> 
        <meta charset="UTF-8"> 
        <title></title> 
        <style type="text/css"> 
            #shape{ 
                margin: 200px 0px 0px 200px; 
                position: relative; 
                 300px; 
                height: 500px; 
                /*border: 1px solid red;*/ 

              overflow: hidden; 
              background-image: url("img/bg/bg1.png"); 
                background-position: center; 
            } 
            #div1{ 
                position: absolute; 
                top:-150px; 
                 0px; 
                height: 0px; 
                border- 150px;  
     
              border-color:white white transparent; 
              border-style: solid; 

            } 
            #rect{ 
                /*border: 1px solid green;*/ 
                position: absolute; 
                top:150px; 
                 300px; 
                height: 200px; 

            } 
            #div2{ 
                position: absolute; 
                top:350px; 
                 0px; 
                height: 0px; 
                border- 150px; 

               border-color:transparent white; 
               border-style: solid; 

            } 
        </style> 
    </head> 
    <body> 
       <div id="shape"> 
           <div id="div1"></div> 
           <div id="rect"></div> 
           <div id="div2"></div> 
       </div> 
    </body> 
    </html>

  • 相关阅读:
    深入理解DB2缓冲池(BufferPool)
    收银台采坑总结
    webpack4的总结
    无心法师-讲解
    cache 缓存的处理
    用es6方式的写的订阅发布的模式
    Skeleton Screen -- 骨架屏--应用
    promise实现原理
    业务线移动端适配方案总结
    vdom,diff,key 算法的了解
  • 原文地址:https://www.cnblogs.com/doubolexiang/p/7222423.html
Copyright © 2011-2022 走看看