css画圆、半圆、椭圆、圆环

╰+哭是因爲堅強的太久メ 2023-08-17 16:53 197阅读 0赞

css画圆

在css中利用border-radius可以画出我们想要的圆
border-radius属性
可以设置盒子四边的圆弧。从上左,上右,下右,下左顺时针依次设置四个属性
也可以单独设置一个方向如border-radius-top-left

1.css画一个圆

首先我们需要一个正方形盒子,border-radius设置弧度的半径为其边长一半即可
代码如下

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <style type="text/css">
  6. .picture{
  7. width: 200px;
  8. height:200px;
  9. background-color: red;
  10. border-radius: 100px;
  11. }
  12. </style>
  13. </head>
  14. <body>
  15. <div class="picture">
  16. </div>
  17. </body>
  18. </html>

如果盒子的长宽不一样,就画成椭圆了

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <style type="text/css">
  6. .picture{
  7. width: 200px;
  8. height:100px;
  9. background-color: red;
  10. border-radius: 100px;
  11. }
  12. </style>
  13. </head>
  14. <body>
  15. <div class="picture">
  16. </div>
  17. </body>
  18. </html>

2.css画圆环

不要背景色,只要边框即可
代码如下

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <style type="text/css">
  6. .picture{
  7. width: 200px;
  8. height:100px;
  9. border:1px solid black;
  10. border-radius: 100px;
  11. }
  12. .picture2{
  13. width: 200px;
  14. height:200px;
  15. border:1px solid black;
  16. border-radius: 100px;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <div class="picture">
  22. </div>
  23. <div class="picture2">
  24. </div>
  25. </body>
  26. </html>

3.css画半圆

画半圆时,只需要两个边有弧度即可,半径为最短边
代码如下

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <style type="text/css">
  6. .picture{
  7. width: 200px;
  8. height:100px;
  9. background-color: green;
  10. border-top-left-radius:100px;
  11. border-top-right-radius:100px;
  12. }
  13. .picture2{
  14. width: 100px;
  15. height:200px;
  16. background-color: red;
  17. border-top-left-radius: 100px;
  18. border-bottom-left-radius: 100px;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div class="picture">
  24. </div>
  25. <div class="picture2">
  26. </div>
  27. </body>
  28. </html>

发表评论

表情:
评论列表 (有 0 条评论,197人围观)

还没有评论,来说两句吧...

相关阅读