资讯专栏INFORMATION COLUMN

css绘制各种各样的形状图形

levinit / 2980人阅读

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

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

1、实心圆

</>复制代码

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

</>复制代码

  1. .ring {
  2. width: 120px;
  3. height: 120px;
  4. border: 10px solid #317ef3;
  5. border-radius: 100%;
  6. box-sizing: border-box;
  7. }
3、半圆

</>复制代码

  1. //上半圆
  2. .top-semicircle {
  3. width: 120px;
  4. height: 60px;
  5. background: #317ef3;
  6. border-radius: 60px 60px 0 0;
  7. /*顺时针方向,四个值依次分别表示左上、右上、右下、左下*/
  8. }
  9. //右半圆
  10. .rt-semicircle {
  11. width: 60px;
  12. height: 120px;
  13. background: #317ef3;
  14. border-radius: 0 60px 60px 0;
  15. }
  16. //左半圆
  17. .lf-semicircle {
  18. width: 60px;
  19. height: 120px;
  20. background: #317ef3;
  21. border-radius: 60px 0 0 60px;
  22. }
  23. //下半圆
  24. .bot-semicircle {
  25. width: 120px;
  26. height: 60px;
  27. background: #317ef3;
  28. border-radius: 0 0 60px 60px;
  29. }
四分之一圆(扇形)

</>复制代码

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

</>复制代码

  1. .love {
  2. width: 100px;
  3. height: 100px;
  4. background: #317ef3;
  5. position: relative;
  6. transform: rotate(45deg);
  7. -webkit-transform: rotate(45deg);
  8. -moz-transform: rotate(45deg);
  9. -o-transform: rotate(45deg);
  10. }
  11. .love::before,.love:after{
  12. content: "";
  13. background: #317ef3;
  14. position: absolute;
  15. }
  16. .love:after {
  17. width: 50px;
  18. height: 100px;
  19. background: #317ef3;
  20. border-radius: 50px 0 0 50px;
  21. right: 99px;
  22. top: 0;
  23. }
  24. .love::before {
  25. width: 100px;
  26. height: 50px;
  27. border-radius: 50px 50px 0 0;
  28. bottom: 99px;
  29. left: 0;
  30. }

原理图奉上

吃豆人

</>复制代码

  1. .eat {
  2. width: 0;
  3. height: 0;
  4. border: 60px solid #317ef3;
  5. border-radius: 100%;
  6. border-right-color: transparent;
  7. }

值得注意的是如果右边框的颜色设置为白色的话,右边会有一条蓝色线条

鸡蛋

</>复制代码

  1. .egg {
  2. width: 100px;
  3. height: 150px;
  4. background: #317ef3;
  5. border-radius: 50px 50px 50px 50px/90px 90px 60px 60px;
  6. }

原理图奉上:

椭圆

</>复制代码

  1. .ellipse1 {
  2. width: 180px;
  3. height: 120px;
  4. background: #317ef3;
  5. border-radius: 100%;
  6. /* border-radius: 90px/60px; */
  7. }

</>复制代码

  1. .ellipse2 {
  2. width: 120px;
  3. height: 180px;
  4. background: #317ef3;
  5. border-radius: 100%;
  6. /* border-radius: 60px/90px; */
  7. }
胶囊

</>复制代码

  1. .capsule1 {
  2. width: 200px;
  3. height: 100px;
  4. background: #317ef3;
  5. border-radius: 50px;
  6. }

</>复制代码

  1. .capsule2 {
  2. width: 100px;
  3. height: 200px;
  4. background: #317ef3;
  5. border-radius: 50px;
  6. }
太极八卦阵图

</>复制代码

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

</>复制代码

  1. .leaf1 {
  2. width: 100px;
  3. height: 100px;
  4. background: #317ef3;
  5. border-radius: 0 100px;
  6. }

</>复制代码

  1. .leaf2 {
  2. width: 100px;
  3. height: 100px;
  4. background: #317ef3;
  5. border-radius: 80px 0px;
  6. }

</>复制代码

  1. .leaf3 {
  2. width: 100px;
  3. height: 100px;
  4. background: #317ef3;
  5. border-radius: 50px 50px 0 50px;
  6. }
五叶花瓣

</>复制代码

</>复制代码

  1. .five-petal {
  2. width: 160px;
  3. height: 160px;
  4. }
  5. .five-petal span {
  6. display: block;
  7. width: 80px;
  8. height: 80px;
  9. background: #317ef3;
  10. border-radius: 0 100px;
  11. transform-origin: 100% 100%;
  12. position: absolute;
  13. }
  14. .five-petal .petal2 {
  15. transform: rotate(72deg);
  16. }
  17. .five-petal .petal3 {
  18. transform: rotate(144deg);
  19. }
  20. .five-petal .petal4 {
  21. transform: rotate(216deg);
  22. }
  23. .five-petal .petal5 {
  24. transform: rotate(288deg);
  25. }
四叶草

</>复制代码

</>复制代码

  1. .four-leaf {
  2. width: 210px;
  3. height: 210px;
  4. position: relative;
  5. }
  6. .four-leaf span {
  7. display: block;
  8. width: 100px;
  9. height: 100px;
  10. background: #317ef3;
  11. position: absolute;
  12. }
  13. .four-leaf span.leaf1 {
  14. left: 0;
  15. top: 0;
  16. border-radius: 50px 50px 0 50px;
  17. }
  18. .four-leaf span.leaf2 {
  19. right: 0;
  20. top: 0;
  21. border-radius: 50px 50px 50px 0;
  22. }
  23. .four-leaf span.leaf3 {
  24. left: 0;
  25. bottom: 0;
  26. border-radius: 50px 0 50px 50px;
  27. }
  28. .four-leaf span.leaf4 {
  29. right: 0;
  30. bottom: 0;
  31. border-radius: 0 50px 50px 50px;
  32. }
无穷符号

</>复制代码

</>复制代码

  1. .infinite {
  2. width: 250px;
  3. position: relative;
  4. }
  5. .infinite span {
  6. width: 100px;
  7. height: 100px;
  8. background: #fff;
  9. border: 2px solid #317ef3;
  10. position: absolute;
  11. }
  12. .infinite .lf {
  13. border-radius: 50px 50px 0 50px;
  14. transform: rotate(-45deg);
  15. left: 0;
  16. }
  17. .infinite .rt {
  18. border-radius: 50px 50px 50px 0;
  19. transform: rotate(45deg);
  20. right: 0;
  21. }
小尾巴

</>复制代码

  1. .xwb1 {
  2. width: 100px;
  3. height: 60px;
  4. border-top: 20px solid #317ef3;
  5. border-radius: 0 60px 0 0;
  6. }

</>复制代码

  1. .xwb2 {
  2. width: 100px;
  3. height: 60px;
  4. border-left: 20px solid #317ef3;
  5. border-radius: 60px 0 0 0;
  6. }
月亮

</>复制代码

  1. .moon {
  2. width: 100px;
  3. height: 100px;
  4. border-left: 30px solid #317ef3;
  5. border-radius: 50px 0 0 50px;
  6. }
立体球型

</>复制代码

  1. .litiqiuxing1 {
  2. width: 100px;
  3. height: 100px;
  4. border-radius: 100%;
  5. background: #317ef3;
  6. background: radial-gradient(circle at 25% 35%, #fff, #317ef3, #071529);
  7. }

</>复制代码

  1. .litiqiuxing2 {
  2. width: 100px;
  3. height: 100px;
  4. border-radius: 100%;
  5. background: #317ef3;
  6. background: radial-gradient(circle at top, #fff, #317ef3, #071529)
  7. }

</>复制代码

  1. .litiqiuxing3 {
  2. width: 100px;
  3. height: 100px;
  4. border-radius: 100%;
  5. background: #317ef3;
  6. background: radial-gradient(circle at left top, #fff 10%, #78a8f2 30%, #0b59ca 60%, #04409a 80%, #202b3a 100%)
  7. }
三角形实现原理

</>复制代码

  1. .triangle-shiyi {
  2. width: 0;
  3. height: 0;
  4. border: 50px solid #317ef3;
  5. border-left-color: red;
  6. border-top-color: aquamarine;
  7. border-right-color: bisque;
  8. }
等腰直角三角

</>复制代码

  1. .dbzj-sanjiao1 {
  2. width: 0;
  3. height: 0;
  4. border-bottom: 100px solid #317ef3;
  5. border-right: 100px solid transparent;
  6. }
  7. .dbzj-sanjiao2 {
  8. width: 0;
  9. height: 0;
  10. border-bottom: 100px solid #317ef3;
  11. border-left: 100px solid transparent;
  12. }

</>复制代码

  1. .dbzj-sanjiao3 {
  2. width: 0;
  3. height: 0;
  4. border-top: 100px solid #317ef3;
  5. border-right: 100px solid transparent;
  6. }
  7. .dbzj-sanjiao4 {
  8. width: 0;
  9. height: 0;
  10. border-top: 100px solid #317ef3;
  11. border-left: 100px solid transparent;
  12. }

</>复制代码

  1. .dbzj-sanjiao5 {
  2. width: 0;
  3. height: 0;
  4. border-bottom: 50px solid #317ef3;
  5. border-left: 100px solid transparent;
  6. /* border-left、border-right决定宽度 */
  7. /* border-top、border-bottom决定高度 */
  8. }
  9. .dbzj-sanjiao6 {
  10. width: 0;
  11. height: 0;
  12. border-bottom: 50px solid #317ef3;
  13. border-right: 100px solid transparent;
  14. }

</>复制代码

  1. .dbzj-sanjiao7 {
  2. width: 0;
  3. height: 0;
  4. border-bottom: 100px solid #317ef3;
  5. border-right: 50px solid transparent;
  6. }
  7. .dbzj-sanjiao8 {
  8. width: 0;
  9. height: 0;
  10. border-bottom: 100px solid #317ef3;
  11. border-left: 50px solid transparent;
  12. }

</>复制代码

  1. .dbzj-sanjiao9 {
  2. width: 0;
  3. height: 0;
  4. border-top: 50px solid #317ef3;
  5. border-right: 100px solid transparent;
  6. }
  7. .dbzj-sanjiao10 {
  8. width: 0;
  9. height: 0;
  10. border-top: 50px solid #317ef3;
  11. border-left: 100px solid transparent;
  12. }
锐角三角形

</>复制代码

  1. .dbzj-sanjiao11 {
  2. width: 0;
  3. height: 0;
  4. border-left: 40px solid transparent;
  5. border-right: 40px solid transparent;
  6. border-bottom: 100px solid #317ef3;
  7. /*三角形的宽度w=left+right,h=bottom*/
  8. }
钝角三角形

</>复制代码

  1. .dbzj-sanjiao12 {
  2. width: 0;
  3. height: 0;
  4. border-bottom: 50px solid #317ef3;
  5. border-right: 100px solid transparent;
  6. position: relative;
  7. }
  8. .dbzj-sanjiao12::before {
  9. content: "";
  10. position: absolute;
  11. left: 0;
  12. top: 0;
  13. border-bottom: 50px solid #fff;
  14. border-right: 20px solid transparent;
  15. }
平行四边形

</>复制代码

  1. .pxsbx1 {
  2. width: 200px;
  3. height: 120px;
  4. background: #317ef3;
  5. color: #fff;
  6. text-align: center;
  7. line-height: 120px;
  8. font-size: 18px;
  9. transform: skewX(30deg);
  10. }

</>复制代码

  1. .pxsbx2 {
  2. width: 200px;
  3. height: 120px;
  4. text-align: center;
  5. line-height: 120px;
  6. position: relative;
  7. font-size: 18px;
  8. color: #fff;
  9. }
  10. .pxsbx2::after {
  11. content: "";
  12. position: absolute;
  13. left: 0;
  14. top: 0;
  15. z-index: -1;
  16. width: 200px;
  17. height: 120px;
  18. background: #317ef3;
  19. transform: skewX(30deg);
  20. }

与上面的平行四边形相比,可以看到该图形中的文字不会发生倾斜,方法是在文字层后添加一个伪元素绘制平行四边。

</>复制代码

  1. .pxsbx3 {
  2. width: 100px;
  3. height: 160px;
  4. background: #317ef3;
  5. transform: skewY(30deg);
  6. }
  7. .pxsbx4 {
  8. width: 100px;
  9. height: 160px;
  10. background: #317ef3;
  11. transform: skewY(-30deg);
  12. }
梯形

</>复制代码

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

</>复制代码

  1. .tixing2 {
  2. width: 100px;
  3. height: 100px;
  4. background: #317ef3;
  5. position: relative;
  6. }
  7. .tixing2::before {
  8. content: "";
  9. width: 0;
  10. height: 0;
  11. border-bottom: 100px solid #317ef3;
  12. border-right: 50px solid transparent;
  13. position: absolute;
  14. left: 100%;
  15. top: 0;
  16. }
边框对话框

</>复制代码

  1. .duihuakuang1 {
  2. width: 200px;
  3. height: 120px;
  4. border: 2px solid #317ef3;
  5. position: relative;
  6. }
  7. .duihuakuang1::before {
  8. content: "";
  9. position: absolute;
  10. left: 40px;
  11. top: 92%;
  12. width: 20px;
  13. height: 20px;
  14. border-right: 2px solid #317ef3;
  15. border-bottom: 2px solid #317ef3;
  16. transform: rotate(45deg);
  17. background: #fff;
  18. }

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

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

相关文章

  • css绘制各种各样形状图形

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

    mingde 评论0 收藏0
  • css绘制各种形状图形(第二版)

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

    CoreDump 评论0 收藏0
  • css绘制各种形状图形(第二版)

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

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

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

    Brenner 评论0 收藏0

发表评论

0条评论

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