0


前端 CSS 经典:弧形边框选项卡

1. 效果图

2. 开始

准备一个元素,将元素左上角,右上角设为圆角。

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>Document</title>
  7. <style>
  8. .tab {
  9. width: 150px;
  10. height: 40px;
  11. margin: 0 auto;
  12. background: #ed6a5e;
  13. border-radius: 10px 10px 0 0;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <div class="tab"></div>
  19. </body>
  20. </html>

然后要在左右两边拼接弧形,我们可以写两个伪元素

  1. .tab::before,
  2. .tab::after {
  3. content: "";
  4. position: absolute;
  5. width: 10px;
  6. height: 10px;
  7. bottom: 0;
  8. }
  9. .tab::before {
  10. left: -10px;
  11. }
  12. .tab::before {
  13. right: -10px;
  14. }

那怎么将这两个元素做成弧形呢,可以使用渐变。

  1. .tab::before {
  2. background: radial-gradient(circle at 0 0, transparent 10px, #ed6a5e 10px);
  3. }
  4. .tab::after {
  5. background: radial-gradient(circle at 100% 0, transparent 10px, #ed6a5e 10px);
  6. }

这下我们有了弧形,那怎么做成效果图的样式呢,最后我们可以使用旋转。

  1. .tab {
  2. transform: perspective(30px) rotateX(20deg);
  3. transform-origin: center bottom;
  4. }

3.完整代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>Document</title>
  7. <style>
  8. .tab {
  9. width: 150px;
  10. height: 40px;
  11. margin: 0 auto;
  12. background: #ed6a5e;
  13. border-radius: 10px 10px 0 0;
  14. position: relative;
  15. transform: perspective(30px) rotateX(20deg);
  16. transform-origin: center bottom;
  17. }
  18. .tab::before,
  19. .tab::after {
  20. content: "";
  21. position: absolute;
  22. width: 10px;
  23. height: 10px;
  24. bottom: 0;
  25. background: #000;
  26. }
  27. .tab::before {
  28. left: -10px;
  29. background: radial-gradient(
  30. circle at 0 0,
  31. transparent 10px,
  32. #ed6a5e 10px
  33. );
  34. }
  35. .tab::after {
  36. right: -10px;
  37. background: radial-gradient(
  38. circle at 100% 0,
  39. transparent 10px,
  40. #ed6a5e 10px
  41. );
  42. }
  43. </style>
  44. </head>
  45. <body>
  46. <div class="tab"></div>
  47. </body>
  48. </html>
标签: 前端 css

本文转载自: https://blog.csdn.net/weixin_64684095/article/details/138960388
版权归原作者 yqcoder 所有, 如有侵权,请联系我们删除。

“前端 CSS 经典:弧形边框选项卡”的评论:

还没有评论