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

Categories

0 votes
446 views
in Technique[技术] by (71.8m points)

css - How to create a triangular shape with curved border?

What I want What I get I want to do this shape using CSS not as an image can I but I get the green shape and I can't get the all background transparent !

#arrowbox:before {
    right: 100%;
    top: 50%;
    border: solid transparent;
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none;
    border-color: rgba(0, 128, 0, 0);
    border-right-color: #008000;
    border-width: 25px;
    margin-top: -25px;
}
See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

You can do it with some perspective and rotation:

.box {
  margin:20px;
  padding:20px calc(50% - 100px); /* this will fix the max width to 2x100px */
  /* the horizontal lines (one on each side)*/
  background:
    linear-gradient(red,red) left,
    linear-gradient(red,red) right;
  background-size:calc(50% - 100px) 2px;
  background-repeat:no-repeat;
  /* */
  text-align:center;
  position:relative;
}
.box::before,
.box::after{
  content:"";
  position:absolute;
  top:-10px; /* lower than 0 to avoid the overlap due to rotation */
  /* same as the padding */
  left:calc(50% - 100px); 
  right:calc(50% - 100px);
  /* */
  bottom:50%;
  border:3px solid red;
  border-bottom:none;
  border-radius:15px 15px 0 0;
  /* adjust here to control the shape  */
  transform:var(--s,scaley(1)) perspective(40px) rotateX(25deg);
  /* */
  transform-origin:bottom;
}
.box::after {
  --s:scaley(-1);
}
<div class="box"> some text here</div>


<div class="box"> more and more <br> text here</div>

<div class="box"> even more <br> and more <br> text here</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...