Vyacheslav Loginov Vyacheslav Loginov - 1 month ago 19
CSS Question

Bordered 5-corners CSS element

I need to create an element like this:

enter image description here

5 corners, border and text in

<span>
element. How can I achieve that result? I have only managed to create the normal element with 4 corners.



.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>




Answer

I've created a single element solution. Basically you use the pseudo-elements ::before to create the tip (same styles as for your main element but rotated by 45°) and ::after to hide the left unwanted box-shadow.

Some additional hints: Don't nest <span> elements and use 0 instead of 0px for CSS zero values.

.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>