如何创建带有弯曲边框的三角形? [英] How to create a triangular shape with curved border?

查看:71
本文介绍了如何创建带有弯曲边框的三角形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想使用CSS来做这种形状而不是图像,但是我可以绿色的形状,我无法使所有背景透明!

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;
}


推荐答案

您可以用一些透视和旋转:

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>

具有倾斜变换的另一个想法:

Another idea with skew transformation:

.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,
.box span::before,
.box span::after{
  content:"";
  position:absolute;
  top:0;
  left:calc(50% - 100px); 
  right:50%;
  bottom:50%;
  border:2px solid red;
  border-bottom:none;
  border-right:none;
  border-radius:10px 0 0 0;
  transform:var(--s,scaleX(1)) skew(-35deg);
  transform-origin:right bottom;
}
.box::after {
  --s:scalex(-1);
}
.box span::before {
  --s:scaleY(-1);
}
.box span::after {
  --s:scale(-1);
}

<div class="box"><span></span> some text here</div>


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

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

这篇关于如何创建带有弯曲边框的三角形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆