• 如何通过CSS绘制三角形和小箭头


    1. 绘制三角形的作用,主要是提供指示性,如下图

     2. 那么如何画出三角形呢?我们先看下border的用法

    <div class="box">div>
    1. .box{
    2. box-sizing: border-box;
    3. height: 200px;
    4. width: 200px;
    5. border-left: 80px solid red;
    6. border-right: 80px solid beige;
    7. border-top: 80px solid green;
    8. border-bottom: 80px solid yellow;
    9. }

     效果如图所示,border为1是,看起来是单纯的直线,如果border的长度过长,就是就会形成如下的情况。如果你把上面的css边框都由80px调成100px。就会形成如下的效果。

    1. .box{
    2. box-sizing: border-box;
    3. height: 200px;
    4. width: 200px;
    5. border-left: 100px solid red;
    6. border-right: 100px solid beige;
    7. border-top: 100px solid green;
    8. border-bottom: 100px solid yellow;
    9. }

     这样我们就得到了4个三角形。那我们如果只想得到其中的1个三角形呢,我们就把其他三个border隐藏掉就好了。

    3. 画出三角形

    <div class="traingle bottom">div>
    1. .traingle{
    2. display: inline-block;
    3. border: solid 50px transparent; /*隐藏边框颜色 控制三角形的长边边长*/
    4. }
    5. .traingle.bottom{
    6. border-top-color: green ; /* top botttom left right 控制三角形方向 */
    7. }

     4. 画出如上图的气泡提示词效果(口诀:内部元素绝对定位,外部元素相对定位

    1. body{
    2. background-color: #f0f0f0;
    3. }
    4. .box{
    5. box-sizing: border-box;
    6. width: 200px;
    7. height: 50px;
    8. line-height: 30px;
    9. position: relative;
    10. padding: 10px;
    11. background-color: white;
    12. border-radius: 8px;
    13. }
    14. .triangle{
    15. position: absolute;
    16. bottom: -30px;
    17. left: 10px;
    18. display: inline-block;
    19. border: 15px solid transparent;
    20. }
    21. .triangle.bottom {
    22. border-top-color: white;
    23. }
    1. <div class="box">
    2. 我是气泡框
    3. <div class="triangle bottom">div>
    4. div>

    5. 绘制小箭头

    只需要使用after再画一个白色三角形,然后再原来绿色三角形的基础上向右偏移即可。 

    1. .box {
    2. padding: 15px;
    3. background-color: #ffffff;
    4. border-radius: 6px;
    5. display: flex;
    6. align-items: center;
    7. justify-content: center;
    8. }
    9. .arrow {
    10. display: inline-block;
    11. margin-right: 10px;
    12. width: 0;
    13. height: 0;
    14. /* Base Style */
    15. border: 16px solid;
    16. border-color: transparent #cddc39 transparent transparent;
    17. position: relative;
    18. }
    19. .arrow::after {
    20. content: "";
    21. position: absolute;
    22. right: -20px;
    23. top: -16px;
    24. border: 16px solid;
    25. border-color: transparent #fff transparent transparent;
    26. }
    27. /*下*/
    28. .arrow.bottom {
    29. transform: rotate(270deg);
    30. }
    31. /*上*/
    32. .arrow.top {
    33. transform: rotate(90deg);
    34. }
    35. /*左*/
    36. .arrow.left {
    37. transform: rotate(180deg);
    38. }
    39. /*右*/
    40. .arrow.right {
    41. transform: rotate(0deg);
    42. }
    1. <div class="box">
    2. <div class="arrow">div>
    3. div>

  • 相关阅读:
    重修之Java-基础篇-数据类型和运算符
    【练习题】二.栈和队列
    Hinton2022年RobotBrains访谈记录
    Redis----布隆过滤器
    element-ul基本使用
    打造千万级流量秒杀第二十六课 限流器:如何实现熔断器和限流器防止宕机和雪崩?
    python类方法和静态方法区别详细讲解
    Git小技巧(持续更新)
    【无标题】
    UML概述及UML类图详解
  • 原文地址:https://blog.csdn.net/yangshuolll/article/details/126726184