Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to add a label on some of my elements on a website and design for a label that is a flag with an inverted V-shaped cut at the bottom.

So far I have this:

HTML

<div class="css-shapes"></div>

CSS

.css-shapes{
    border-left: 99px solid #f00fff;
    border-right: 99px solid #f00fff;
    border-bottom: 39px solid transparent;
}

http://jsfiddle.net/yhexkm4u/2/

However, I need the background to be white and border around this shape in purple and 1px. I was trying to fit the same shape just in white inside of this one, but everything got messy and didn't go as expected.

Maybe it is a wrong approach, but I want to end up with labels that would look something like this:

image

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
636 views
Welcome To Ask or Share your Answers For Others

1 Answer

With CSS:

You can use CSS transforms on pseudo elements to create the background with a transparent inverted triangle at the bottom:

body{background:url('http://lorempixel.com/image_output/food-q-c-640-480-1.jpg');background-size:cover;}
p{
  position: relative;
  width: 150px; height: 150px;
  overflow: hidden;
  border-top:3px solid #EF0EFE;
}
p:before, p:after{
  content: '';
  position: absolute;
  top: -3px;
  height: 100%; width: 50%;
  z-index: -1;
  border:2px solid #EF0EFE;
  box-sizing:border-box;
}
p:before{
  left: 0;  
  transform-origin: 0 0;
  transform: skewY(-20deg);
  border-width:0 0 4px 3px;
}
p:after{
  right: 0;
  transform-origin: 100% 0;
  transform: skewY(20deg);
  border-width:0 3px 4px 0;
}
<p>Some text ... </p>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...