css实现有边框的三角形

女生的网名这么多〃 提交于 2020-01-24 05:06:50

1、html

    <!--向上的三角形-->
    <div class="border-up">
      <span></span>
    </div>
    <!--向下的三角形-->
    <div class="border-down">
      <span></span>
    </div>
    <!--向左的三角形-->
    <div class="border-left">
      <span></span>
    </div>
    <!--向右的三角形-->
    <div class="border-right">
      <span></span>
    </div>

2、css

.border-up {
        width: 0;
        height: 0;
        border-left: 30px solid transparent;
        border-right: 30px solid transparent;
        border-bottom: 30px solid #333;
        position: relative;
        margin: 50px auto;
      }
      .border-up span {
        display: block;
        width: 0;
        height: 0;
        border-left: 28px solid transparent;
        border-right: 28px solid transparent;
        border-bottom: 28px solid palevioletred;
        position: absolute;
        left: -28px;
        top: 1px;
      }
      .border-down {
        width: 0;
        height: 0;
        border-left: 30px solid transparent;
        border-right: 30px solid transparent;
        border-top: 30px solid #333;
        position: relative;
        margin: 50px auto;
      }
      .border-down span {
        display: block;
        width: 0;
        height: 0;
        border-left: 28px solid transparent;
        border-right: 28px solid transparent;
        border-top: 28px solid palevioletred;
        position: absolute;
        left: -28px;
        top: -29px;
      }
      .border-left {
        width: 0;
        height: 0;
        border-bottom: 30px solid transparent;
        border-right: 30px solid #333;
        border-top: 30px solid transparent;
        position: relative;
        margin: 50px auto;
      }
      .border-left span {
        display: block;
        width: 0;
        height: 0;
        border-bottom: 28px solid transparent;
        border-right: 28px solid palevioletred;
        border-top: 28px solid transparent;
        position: absolute;
        left: 1px;
        top: -28px;
      }
      .border-right {
        width: 0;
        height: 0;
        border-left: 30px solid #333;
        border-bottom: 30px solid transparent;
        border-top: 30px solid transparent;
        position: relative;
        margin: 50px auto;
      }
      .border-right span {
        display: block;
        width: 0;
        height: 0;
        border-left: 28px solid palevioletred;
        border-bottom: 28px solid transparent;
        border-top: 28px solid transparent;
        position: absolute;
        left: -29px;
        top: -28px;
      }

 3、效果图

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!