最新公告
  • 欢迎您光临起源地模板网,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!立即加入钻石VIP
  • 用css画立体锥形图

    正文概述 掘金(陈锋)   2021-01-08   1128

    事情是这样的,最近在弄一个项目,关于可视化的(实际上最近其他几篇分享也是同一个项目),里面有一个立体的锥形图,设计稿长这样:

    用css画立体锥形图

    准确来讲,其实这也不算立体的,只是视觉上有立体效果,姑且就认为是立体图吧。

    一开始,我是用ecahrts的漏斗图制作的,效果是这样(直接从echarts 官网截的实例图。颜色问题请忽略):

    用css画立体锥形图

    个人觉还行,但领导是在觉得丑,无奈之下,只能选择其他方案。从网上查找相关的资料,并没有发现相关实例可参考,只有highcharts图表库有一个3d的锥形图,但真的很丑,且没办法修改成我所需要的样式,我只好另寻他路了。

    在否定了直接切图这个方案后,我开始向社群的大佬们请教,找到了新的方向,通过CSS画出来。

    show me the code,这里给出我的方法:

    //vue template
    <div class="circle">
      <div class="one gh">
        <span class="arc" />
      </div>
      <div class="two gh">
        <span class="ellipse" />
        <span class="arc" />
      </div>
      <div class="three gh">
        <span class="ellipse" />
        <span class="arc" />
      </div>
      <div class="four gh">
        <span class="ellipse" />
        <span class="arc" />
      </div>
    </div>
    
    //vue scss
    .circle {
        width: 150px;
        height: 100%;
        .gh {
          border-style: solid;
          height: 0;
          margin: 0 auto;
          position: relative;
        }
        .arc {
          position: absolute;
          left: 50%;
          transform: translateX(-50%);
          height: 8px;
          border-radius: 50%;
        }
        .ellipse {
          position: absolute;
          left: 50%;
          transform: translateX(-50%);
          height: 4px;
          border-radius: 50%;
          top: -2px;
        }
        .one {
          border-color: transparent transparent #cda01e transparent;
          border-width: 0 12px 20px 12px;
          width: 24px;
          .arc {
            bottom: -24px;
            width: 24px;
            background-color: #cda01e;
          }
        }
        .two {
          border-color: transparent transparent #8540f6 transparent;
          border-width: 10px 12px 30px 12px;
          width: 54px;
          .arc {
            bottom: -34px;
            width: 54px;
            background-color: #8540f6;
          }
          .ellipse {
            width: 30px;
            background-color: #4511a2;
          }
        }
        .three {
          border-color: transparent transparent #4b78f2 transparent;
          border-width: 10px 12px 30px 12px;
          width: 84px;
          .arc {
            bottom: -34px;
            width: 84px;
            background-color: #4b78f2;
          }
          .ellipse {
            width: 60px;
            background-color: #1f4094;
          }
        }
        .four {
          border-color: transparent transparent #28f8c3 transparent;
          border-width: 10px 12px 40px 12px;
          width: 114px;
          .arc {
            bottom: -44px;
            width: 114px;
            background-color: #28f8c3;
          }
          .ellipse {
            height: 6px;
            top: -3px;
            width: 90px;
            background-color: #006384;
          }
        }
      }
    

    简单说明下:因为css可以画三角形,圆形等几何图形,而我要实现的这个图,可以认为是三角形,圆弧,梯形组成,这样一想,好像也没啥问题。我先将图分成了四块,可以看出,每块都有一个主体部分(三角形或梯形)和底部的圆弧(可以认为是椭圆),另外除第一块的锥尖,其余三块还有顶部的视觉阴影效果(椭圆)。

    经过排版定位,实际效果如下:

    用css画立体锥形图

    看起来还蛮像的吧,当然如果你有好的实现方式,请指教!


    起源地下载网 » 用css画立体锥形图

    常见问题FAQ

    免费下载或者VIP会员专享资源能否直接商用?
    本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
    提示下载完但解压或打开不了?
    最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。若排除这种情况,可在对应资源底部留言,或 联络我们.。
    找不到素材资源介绍文章里的示例图片?
    对于PPT,KEY,Mockups,APP,网页模版等类型的素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。 同样地一些字体文件也是这种情况,但部分素材会在素材包内有一份字体下载链接清单。
    模板不会安装或需要功能定制以及二次开发?
    请QQ联系我们

    发表评论

    还没有评论,快来抢沙发吧!

    如需帝国cms功能定制以及二次开发请联系我们

    联系作者

    请选择支付方式

    ×
    迅虎支付宝
    迅虎微信
    支付宝当面付
    余额支付
    ×
    微信扫码支付 0 元