带边框的 5 个角 CSS 元素

Bordered 5-corners CSS element

我需要创建这样的元素:

<span> 元素中的 5 个角、边框和文本。我怎样才能达到那个结果?我只成功创建了具有 4 个角的普通元素。

.pin {
  position: absolute;
  top: 7px;
  right: 7px;
  display: inline-block;
  min-height: 34px;
  min-width: 42px;
  vertical-align: top;
  padding: 0px 4px;
  color: #fff;
  text-align: center;
  line-height: 1.2;
  text-transform: uppercase;
  border-radius: 4px;
  box-shadow: inset 0px 0px 0px 1px rgba(255, 255, 255, 0.28);
}
.pin__green {
  background-color: #689f39;
  border: 1px solid #59902b;
}
.pt {
  font-size: 13px;
  font-family: 'PT Sans';
  display: block;
  margin-top: 10px;
}
<span class="pin pin__green">
  <span class="pt">
    <span>2</span>
    <span>new</span>
  </span>
</span>

我已经创建了一个单元素解决方案。基本上你使用伪元素 ::before 来创建提示(与你的主要元素相同的样式,但旋转了 45°)和 ::after 来隐藏左边不需要的框阴影。

一些额外的提示:不要嵌套 <span> 元素并使用 0 而不是 0px 作为 CSS 零值。

.pin {
  position: relative;
  display: inline-block;
  height: 34px;
  min-width: 42px;
  padding: 0 10px 0 2px;
  margin-left: 20px;
  color: #fff;
  font-size: 13px;
  font-family: Arial;
  text-align: center;
  line-height: 34px;
  text-transform: uppercase;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}
.pin-green {
  background-color: green;
  border: 1px solid green;
  border-left: 0 solid;
}
/* the tip */

.pin::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 3px;
  height: 25px;
  width: 25px;
  background-color: green;
  border: 1px solid green;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
  z-index: -1;
  transform: rotate(45deg);
}
/* hide the left box-shadow */

.pin::after {
  content: "";
  position: absolute;
  left: 0;
  top: 2px;
  height: 30px;
  width: 2px;
  background-color: green;
}
<div class="pin pin-green">2 new</div>

SVG

使用 svg 创建此形状要容易得多:
文本元素有 tspan 个元素而不是 span 元素

body {
  background-color: #ddd;
}
.greenButtonText {
  font-size: 25px;
  fill: white;
}
<svg viewBox="-5 -5 110 60" width="60px">
  <path stroke-linejoin="round" stroke-width="5" stroke="#689f39" fill="#689f39" d="M0,25 25,0 100,0 100,50 25,50z" />
  <path stroke-linejoin="round" stroke-width="2" stroke="#92C567" fill="none" d="M0,25 25,0 100,0 100,50 25,50z" />
  <text class="greenButtonText" x="25" y="32">
    <tspan>2</tspan>
    <tspan font-size="20">NEW</tspan>
  </text>
</svg>

更大的副本:

body {
  background-color: #ddd;
}
.greenButtonText {
  font-size: 25px;
  fill: white;
}
<!---Copy for display only--->
<svg viewBox="-5 -5 110 60" width="150px">
  <path stroke-linejoin="round" stroke-width="5" stroke="#689f39" fill="#689f39" d="M0,25 25,0 100,0 100,50 25,50z" />
  <path stroke-linejoin="round" stroke-width="1" stroke="#92C567" fill="none" d="M0,25 25,0 100,0 100,50 25,50z" />
  <text class="greenButtonText" x="25" y="32">
    <tspan>2</tspan>
    <tspan font-size="20">NEW</tspan>
  </text>
</svg>