Adding border to CSS triangle [duplicate]

扶醉桌前 提交于 2019-11-30 19:15:16

One way to do it is the create an inner triangle which is smaller.

.triangle-left {
    width: 0;
    height: 0;
    border-top: 23px solid transparent;
    border-bottom: 23px solid transparent;
    border-right: 23px solid red;
}

.inner-triangle {
    position: relative;
    top: -20px;
    left: 2px;
    width: 0;
    height: 0;
    border-top: 20px solid transparent;
    border-bottom: 20px solid transparent;
    border-right: 20px solid blue;
}
<div class="triangle-left">
    <div class="inner-triangle"></div>
</div>
joncampbell

This is how I would do it.

.triangle-left {
  width: 0;
  height: 0;
  border-top: 22px solid transparent;
  border-bottom: 22px solid transparent;
  border-right: 22px solid black;
  position: relative;
}

.triangle-left:after {
  content: '';
  width: 0;
  height: 0;
  border-top: 21px solid transparent;
  border-bottom: 21px solid transparent;
  border-right: 21px solid #dddddd;
  position: absolute;
  top: -21px;
  left: 1px;
}
<div class="triangle-left"></div>

Here it is on JSFiddle.

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