【问题标题】:Border around a div with a triangle point at the bottom底部有一个三角形点的 div 边框
【发布时间】:2017-03-14 18:29:09
【问题描述】:

有没有办法在 CSS 中实现这个边框?我有一个带有项目符号列表的 DIV,我需要将它包裹在像图像一样的边框中。

【问题讨论】:

标签: html css


【解决方案1】:

你可以先创建一个除border-bottom之外的有边框的元素,然后使用:before:after伪元素在底部添加三角形边框。

div {
  width: 200px;
  height: 150px;
  border: 1px solid black;
  border-bottom: none;
  position: relative;
  background: white;
  margin: 20px;
}
div:after, div:before {
  content: '';
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 50px 101px 0 101px;
  border-color: black transparent transparent transparent;
  top: 100%;
  left: -1px;
  position: absolute;
}
div:after {
  border-color: white transparent transparent transparent;
  top: calc(100% - 1px);
  
}
<div></div>

【讨论】:

    【解决方案2】:

    看看这个Fiddle

    基本上把这个css添加到一个div中:

    #base {
      background: red;
      display: inline-block;
      height: 55px;
      margin-left: 20px;
      margin-top: 55px;
      position: relative;
      width: 100px;
    }
    
    #base:after {
      border-bottom: 35px solid red;
      border-left: 50px solid transparent;
      border-right: 50px solid transparent;
      content: "";
      height: 0;
      left: 0;
      position: absolute;
      top: 54px;
      width: 0;
      -ms-transform: rotate(180deg);
      -webkit-transform: rotate(180deg);
      transform: rotate(180deg);
    }
    

    【讨论】:

      【解决方案3】:

      试试这个:

       .down-arrow {
          display: inline-block;
          position: relative;
          background: darkcyan;
          padding: 15px 0;
          width: 200px;
          text-align: center;
      }
      .down-arrow:after {
          content: '';
          display: block;  
          position: absolute;
          left: 0;
          top: 100%;
          width: 0;
          height: 0;
          border-top: 20px solid darkcyan;
          border-right: 100px solid transparent;
          border-bottom: 0 solid transparent;
          border-left: 100px solid transparent;
      }
      

      DEMO HERE

      【讨论】:

      【解决方案4】:

      这是盒子的代码:

      .box {
          background: #fff;
          border: 1px solid #000;
          display: inline-block;
          height: 55px;
          margin-left: 20px;
          margin-top: 55px;
          position: relative;
          width: 100px;
      }
      
      .box:after {
          border-top: 35px solid #fff;
          border-left: 50px solid transparent;
          border-right: 50px solid transparent;
          content: '';
          height: 0;
          left: 0;
          position: absolute;
          top: 55px;
          width: 0;
      }
      .box:before {
          border-top: 35px solid #000;
          border-left: 50px solid transparent;
          border-right: 50px solid transparent;
          content: '';
          height: 0;
          left: 0;
          position: absolute;
          top: 56px;
          width: 0;
      }
      <div class="box">
      </div>

      希望对你有帮助

      【讨论】:

        猜你喜欢
        • 2015-10-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-12
        • 1970-01-01
        • 1970-01-01
        • 2023-03-14
        相关资源
        最近更新 更多