资讯专栏INFORMATION COLUMN

css绘制各种形状图形(第二版)

yibinnn / 1154人阅读

摘要:虽然我们现在大都使用字体图标或者图片,似乎使用来做图标意义不是很大,但怎么实现这些图标用到的一些技巧及思路是很值得我们的学习。

</>复制代码

  1. 虽然我们现在大都使用字体图标或者svg图片,似乎使用 CSS 来做图标意义不是很大,但怎么实现这些图标用到的一些技巧及思路是很值得我们的学习。
一、实心圆

</>复制代码

  1. .circle {
  2. width: 120px;
  3. height: 120px;
  4. background: #8BC34A;
  5. border-radius: 100%;
  6. }
二、圆环(空心圆)

</>复制代码

  1. .ring {
  2. width: 100px;
  3. height: 100px;
  4. border: 10px solid #8BC34A;
  5. border-radius: 100%;
  6. }
三、椭圆

</>复制代码

  1. .ellipsis {
  2. width: 200px;
  3. height: 120px;
  4. background: #8BC34A;
  5. border-radius: 100px/60px;
  6. }
四、半圆

</>复制代码

  1. .top-semicircle {
  2. width: 120px;
  3. height: 60px;
  4. background: #8BC34A;
  5. border-radius: 60px 60px 0px 0px;
  6. }
  7. .right-semicircle {
  8. width: 60px;
  9. height: 120px;
  10. background: #8BC34A;
  11. border-radius: 0 60px 60px 0;
  12. }
  13. .bottom-semicircle {
  14. width: 120px;
  15. height: 60px;
  16. background: #8BC34A;
  17. border-radius: 0 0 60px 60px;
  18. }
  19. .left-semicircle {
  20. width: 60px;
  21. height: 120px;
  22. background: #8BC34A;
  23. border-radius: 60px 0 0 60px;
  24. }
五、四分之一圆(扇形)

</>复制代码

  1. .toplf-sector,
  2. .toprt-sector,
  3. .bottomlf-sector,
  4. .bottomrt-sector {
  5. width: 60px;
  6. height: 60px;
  7. background: #8BC34A;
  8. }
  9. .toplf-sector {
  10. border-radius: 60px 0 0 0;
  11. }
  12. .toprt-sector {
  13. border-radius: 0 60px 0 0;
  14. }
  15. .bottomlf-sector {
  16. border-radius: 0 0 0 60px;
  17. }
  18. .bottomrt-sector {
  19. border-radius: 0 0 60px 0;
  20. }
六、心形

</>复制代码

  1. .heart-shaped {
  2. width: 80px;
  3. height: 80px;
  4. background: #8BC34A;
  5. position: relative;
  6. transform: rotate(45deg);
  7. }
  8. .heart-shaped::before {
  9. content: "";
  10. width: 40px;
  11. height: 80px;
  12. background: #8BC34A;
  13. border-radius: 40px 0 0 40px;
  14. position: absolute;
  15. right: 99%;
  16. top: 0;
  17. }
  18. .heart-shaped::after {
  19. content: "";
  20. width: 80px;
  21. height: 40px;
  22. background: #8BC34A;
  23. border-radius: 40px 40px 0 0;
  24. position: absolute;
  25. left: 0;
  26. bottom: 99%;
  27. }
七、鸡蛋

</>复制代码

  1. .egg {
  2. width: 150px;
  3. height: 200px;
  4. background: #8BC34A;
  5. border-radius: 75px 75px 75px 75px / 130px 130px 70px 70px;
  6. }
八、太极八卦阵图

</>复制代码

  1. .taiji {
  2. width: 140px;
  3. height: 70px;
  4. border: 2px solid #8BC34A;
  5. border-bottom: 70px solid #8BC34A;
  6. border-radius: 100%;
  7. position: relative;
  8. }
  9. .taiji::before {
  10. content: "";
  11. position: absolute;
  12. left: 0;
  13. top: 50%;
  14. width: 20px;
  15. height: 20px;
  16. background: #fff;
  17. border: 25px solid #8BC34A;
  18. border-radius: 100%;
  19. }
  20. .taiji::after {
  21. content: "";
  22. position: absolute;
  23. right: 0;
  24. top: 50%;
  25. width: 20px;
  26. height: 20px;
  27. background: #8BC34A;
  28. border: 25px solid #fff;
  29. border-radius: 100%;
  30. }
九、叶子(花瓣)

</>复制代码

  1. .leaf1 {
  2. width: 80px;
  3. height: 80px;
  4. background: #8BC34A;
  5. border-radius: 0 80px;
  6. }

</>复制代码

  1. .leaf2 {
  2. width: 80px;
  3. height: 80px;
  4. background: #8BC34A;
  5. border-radius: 40px 40px 0 40px;
  6. }
十、五叶花瓣

</>复制代码

  1. .five-flower {
  2. position: relative;
  3. width: 300px;
  4. height: 280px;
  5. }
  6. .five-flower .petal {
  7. display: block;
  8. width: 120px;
  9. height: 120px;
  10. background: #8BC34A;
  11. border-radius: 0 120px;
  12. position: absolute;
  13. transform-origin: 100% 100%;
  14. }
  15. .five-flower .petal1 {
  16. transform: rotate(72deg);
  17. }
  18. .five-flower .petal2 {
  19. transform: rotate(144deg);
  20. }
  21. .five-flower .petal3 {
  22. transform: rotate(216deg);
  23. }
  24. .five-flower .petal4 {
  25. transform: rotate(288deg);
  26. }
十一、牵牛花

</>复制代码

  1. .qiannuhua {
  2. position: relative;
  3. width: 200px;
  4. height: 200px;
  5. margin-left: 140px;
  6. }
  7. .qiannuhua .petal {
  8. display: block;
  9. width: 120px;
  10. height: 120px;
  11. background: #8BC34A;
  12. border-radius: 0 120px;
  13. position: absolute;
  14. transform-origin: 0% 100%
  15. }
  16. .qiannuhua .petal1 {
  17. transform: rotate(72deg);
  18. }
  19. .qiannuhua .petal2 {
  20. transform: rotate(144deg);
  21. }
  22. .qiannuhua .petal3 {
  23. transform: rotate(216deg);
  24. }
  25. .qiannuhua .petal4 {
  26. transform: rotate(288deg);
  27. }
十二、风车

</>复制代码

  1. .fengche {
  2. position: relative;
  3. width: 200px;
  4. height: 200px;
  5. }
  6. .fengche .petal {
  7. display: block;
  8. width: 120px;
  9. height: 120px;
  10. background: #8BC34A;
  11. border-radius: 0 120px;
  12. position: absolute;
  13. transform-origin: 30% 100%
  14. }
  15. .fengche .petal1 {
  16. transform: rotate(72deg);
  17. }
  18. .fengche .petal2 {
  19. transform: rotate(144deg);
  20. }
  21. .fengche .petal3 {
  22. transform: rotate(216deg);
  23. }
  24. .fengche .petal4 {
  25. transform: rotate(288deg);
  26. }
十四、小尾巴

</>复制代码

  1. .xwb1 {
  2. width: 20px;
  3. height: 30px;
  4. border-left: 8px solid #8BC34A;
  5. border-radius: 30px 0 0 0;
  6. }
十五、箭头

</>复制代码

  1. .xwb2 {
  2. width: 0;
  3. height: 0;
  4. border-bottom: 10px solid #8BC34A;
  5. border-left: 10px solid transparent;
  6. position: relative;
  7. transform: rotate(8deg);
  8. }
  9. .xwb2::after {
  10. content: "";
  11. width: 20px;
  12. height: 18px;
  13. border-right: 5px solid #8BC34A;
  14. border-radius: 0px 40px 0 0;
  15. position: absolute;
  16. left: -30px;
  17. bottom: -15px;
  18. transform: rotate(-45deg);
  19. }
十六、月亮

</>复制代码

  1. .moon {
  2. width: 80px;
  3. height: 120px;
  4. border-left: 40px solid #8BC34A;
  5. border-radius: 60px;
  6. }
十六、三角形

</>复制代码

  1. .triangle-bot {
  2. width: 0;
  3. height: 0;
  4. border: 40px solid transparent;
  5. border-bottom-color: #8BC34A;
  6. }
  7. .triangle-top {
  8. width: 0;
  9. height: 0;
  10. border: 40px solid transparent;
  11. border-top-color: #8BC34A;
  12. }
  13. .triangle-lf {
  14. width: 0;
  15. height: 0;
  16. border: 40px solid transparent;
  17. border-left-color: #8BC34A;
  18. }
  19. .triangle-rt {
  20. width: 0;
  21. height: 0;
  22. border: 40px solid transparent;
  23. border-right-color: #8BC34A;
  24. }

</>复制代码

  1. .triangle-toplf,
  2. .triangle-toprt,
  3. .triangle-bottomlf,
  4. .triangle-bottomrt {
  5. width: 0;
  6. height: 0;
  7. }
  8. .triangle-toplf {
  9. border-top: 120px solid #8BC34A;
  10. border-right: 120px solid transparent;
  11. }
  12. .triangle-toprt {
  13. border-top: 120px solid #8BC34A;
  14. border-left: 120px solid transparent;
  15. }
  16. .triangle-bottomlf {
  17. border-bottom: 120px solid #8BC34A;
  18. border-right: 120px solid transparent;
  19. }
  20. .triangle-bottomrt {
  21. border-bottom: 120px solid #8BC34A;
  22. border-left: 120px solid transparent;
  23. }

</>复制代码

  1. .triangle1 {
  2. border-bottom: 120px solid #8BC34A;
  3. border-right: 60px solid transparent;
  4. }
  5. .triangle2 {
  6. border-top: 120px solid #8BC34A;
  7. border-left: 60px solid transparent;
  8. }
  9. .triangle3 {
  10. border-top: 60px solid #8BC34A;
  11. border-right: 120px solid transparent;
  12. }
  13. .triangle4 {
  14. border-top: 60px solid #8BC34A;
  15. border-left: 120px solid transparent;
  16. }

</>复制代码

  1. .triangle5 {
  2. border-top: 80px solid #8BC34A;
  3. border-left: 40px solid transparent;
  4. border-right: 40px solid transparent;
  5. }
十七、梯形

</>复制代码

  1. .tixing1 {
  2. border-bottom: 100px solid #8BC34A;
  3. border-left: 60px solid transparent;
  4. border-right: 60px solid transparent;
  5. width: 100px;
  6. height: 0;
  7. }

</>复制代码

  1. .tixing2 {
  2. border-bottom: 120px solid #8BC34A;
  3. border-right: 120px solid transparent;
  4. width: 80px;
  5. }
十八、边框对话框

</>复制代码

  1. .duihuakuang {
  2. width: 200px;
  3. height: 100px;
  4. border: 2px solid #8BC34A;
  5. border-radius: 6px;
  6. position: relative;
  7. }
  8. .duihuakuang::before {
  9. content: "";
  10. width: 20px;
  11. height: 20px;
  12. background: #fff;
  13. border-right: 2px solid #8BC34A;
  14. border-bottom: 2px solid #8BC34A;
  15. position: absolute;
  16. left: 30%;
  17. top: 100%;
  18. transform: rotate(45deg);
  19. margin-top: -10px;
  20. }
十九、锁

</>复制代码

  1. .suo {
  2. width: 200px;
  3. height: 160px;
  4. background: #8BC34A;
  5. border-radius: 30px;
  6. position: relative;
  7. }
  8. /*锁孔*/
  9. .suo::before {
  10. content: "";
  11. width: 25px;
  12. height: 50px;
  13. background: #fff;
  14. position: absolute;
  15. left: 50%;
  16. top: 50%;
  17. border-radius: 25px;
  18. transform: translate(-50%, -50%);
  19. }
  20. /*锁把*/
  21. .suo::after {
  22. content: "";
  23. width: 80px;
  24. height: 70px;
  25. border: 20px solid #8BC34A;
  26. background: #fff;
  27. border-radius: 60px 60px 0 0;
  28. position: absolute;
  29. left: 50%;
  30. bottom: 89%;
  31. transform: translateX(-50%);
  32. }
二十、立体球型

</>复制代码

  1. .qiu1 {
  2. width: 120px;
  3. height: 120px;
  4. background: #8BC34A;
  5. background-image: radial-gradient(at 20% 30%, #e5ffc7, #75af33, #375f0a);
  6. border-radius: 100%;
  7. }
二十一、圆柱

</>复制代码

</>复制代码

  1. .cylinder {
  2. position: relative;
  3. transform: rotateX(70deg);
  4. }
  5. .ellipse {
  6. width: 100px;
  7. height: 100px;
  8. background: deepskyblue;
  9. border-radius: 50px;
  10. }
  11. .rectangle {
  12. width: 100px;
  13. height: 400px;
  14. position: absolute;
  15. opacity: 0.6;
  16. background: deepskyblue;
  17. top: 0;
  18. left: 0;
  19. border-radius: 50px;
  20. z-index: -1;
  21. }

更多形状图形持续更新,欢迎大家讨论提出问题
(CSS渐变绘制切角效果)

参考文章:
http://www.imooc.com/article/...

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/53923.html

相关文章

  • css绘制各种形状图形二版

    摘要:虽然我们现在大都使用字体图标或者图片,似乎使用来做图标意义不是很大,但怎么实现这些图标用到的一些技巧及思路是很值得我们的学习。 虽然我们现在大都使用字体图标或者svg图片,似乎使用 CSS 来做图标意义不是很大,但怎么实现这些图标用到的一些技巧及思路是很值得我们的学习。 一、实心圆 showImg(https://segmentfault.com/img/bVbsV6v?w=171&h...

    CoreDump 评论0 收藏0
  • 翻译 | 编写SVG的口袋指南(上)

    摘要:元素元素归属于容器和结构元素,在文档内允许嵌套使用独立的片段。如果包含葡萄的组被移动到文档的末尾,它将出现在西瓜的前面。例如,将葡萄的茎的路径移动到组的末尾将导致茎在顶部。 作者:DDU(沪江前端开发工程师)本文是原文翻译,转载请注明作者及出处。 简介 Scalable Vector Graphics (SVG)是在XML中描述二维图形的语言。这些图形由路径,图片和(或)文本组成,并能...

    Brenner 评论0 收藏0
  • 翻译 | 编写SVG的口袋指南(上)

    摘要:元素元素归属于容器和结构元素,在文档内允许嵌套使用独立的片段。如果包含葡萄的组被移动到文档的末尾,它将出现在西瓜的前面。例如,将葡萄的茎的路径移动到组的末尾将导致茎在顶部。 作者:DDU(沪江前端开发工程师)本文是原文翻译,转载请注明作者及出处。 简介 Scalable Vector Graphics (SVG)是在XML中描述二维图形的语言。这些图形由路径,图片和(或)文本组成,并能...

    linkFly 评论0 收藏0
  • css绘制各种各样的形状图形

    摘要:我们在编写前端代码时,经常会遇到各种各样的形状图形如边框对话框,三角形,平行四边形圆角边框圆形四叶草花瓣等,除了用背景图片雪碧图或精灵图定位引用和插入图片的方法,我们还可以用边框圆角渐变和定位的方法结合使用,绘制各种各样的形状图形。 我们在编写前端代码时,经常会遇到各种各样的形状图形(如:边框对话框,三角形,平行四边形、圆角边框、圆形、四叶草、花瓣等),除了用背景图片(css雪碧图或c...

    mingde 评论0 收藏0

发表评论

0条评论

yibinnn

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<