zoukankan      html  css  js  c++  java
  • 使用css3制作正方形、三角形、扇形和饼状图

    1.利用边框制作正方形

    如果将盒容器的width和height设置为0,并为每条边设置一个较粗的width值和彼此不同的颜色,最终会得到四个被拼接在一起三角形,它们分别指向不同的颜色。

    html代码:<div id="square">11</div>

    css3代码:

        #square{
            0;
            height:0;
            border-100px;
            border-style:solid;
            border-color: red blue green yellow;
            line-height:99em;
            overflow:hidden;
            cursor:pointer;
            margin: 30px auto;
          }

    显示效果:

    由图可见,四个三角形指向不同方向。

    2.当我们对四个三角形的其中三个设置颜色为透明即transparent,即可得到一个三角形

    html:

    <div id="triangle">11</div>

    css:

    #triangle{
      0;
      height:0;
      border-100px;
      border-style:solid;
      border-color:red transparent transparent transparent;
      line-height:99em;
      overflow:hidden;
      cursor:pointer;
      margin: 30px auto;
    }

    效果:

    3.大家应该知道css3中引入了圆角属性(border-radius),一旦设置这个值,边框即会出现圆角。同样,我们对正方形设置圆角,即可得到饼状图

    html:<div id="circle">11</div>

    css:

    #circle{

    0;
    height:0;
    border-radius:100px;
    border-100px;
    border-style:solid;
    border-color: red blue green yellow;
    line-height:99em;
    overflow:hidden;
    cursor:pointer;
    margin: 30px auto;


    }

    效果:

    4.同样我们对其中三个边框设置透明色即可得到扇形

    html:<div id="fan">11</div>

    css:

    #fan{

    0;
    height:0;
    border-radius:100px;
    border-100px;
    border-style:solid;
    border-color:red transparent transparent transparent;
    line-height:99em;
    overflow:hidden;
    cursor:pointer;
    margin: 30px auto;

    }

    效果:

  • 相关阅读:
    [包计划] date-fns
    [包计划] create-react-app
    [包计划] js-cookie
    [包计划] cheerio
    [包计划] 30-seconds-of-code
    new
    [源计划] array-first
    [源计划] is-sorted
    [源计划] array-flatten
    images
  • 原文地址:https://www.cnblogs.com/qduanlu/p/2835245.html
Copyright © 2011-2022 走看看