微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

有没有办法用 CSS 为箭头形状添加边框?

如何解决有没有办法用 CSS 为箭头形状添加边框?

我有一个仅用 CSS 创建的箭头状形状。我想对它应用一个边框,如果可能的话,还有一个框阴影。我试过关注 this answer,但它不起作用。我还想知道是否有办法使左侧的白色三角形(赋予箭头形状的三角形)透明而不是白色。

这就是我想要实现的目标:

enter image description here

这就是我所拥有的。如您所见,我只缺少边框和阴影:

enter image description here

.Box {
  width: 180px;
  height: 30px;
  background: -webkit-linear-gradient(-211.23000000000002deg,#B07537 0,#F0B971 100%);
  background: -moz-linear-gradient(301.23deg,#F0B971 100%);
  background: linear-gradient(301.23deg,#F0B971 100%);
  text-align: center;
  color: #fff;
  position: absolute;
  display: table;
  z-index: 1;
  top: 20px;
  right: 7px;
  filter: drop-shadow(0px 3px 4px rgba(0,0.25));
}

.Box span {
  display: table-cell;
  vertical-align: middle;
  font-size: 1em;
  font-weight: 500;
}

.Box:before {
  content: '';
  position: absolute;
  border-left: 15px solid white;
  border-top: 15px solid transparent;
  border-bottom: 17px solid transparent;
  left: 0px;
  top: 0px;
  width: 0;
  height: 0;
  display: block;
}
<div class="Box">
  <span>Text</span>
</div>

解决方法

这是我可以用纯 css 实现的最接近的事情。我希望它至少可以帮助你一点。让我知道它确实如此。

.box{
  font-size:20px;
  position:relative;
  display:inline-block;
  margin:5em;
  text-align:center;
  filter: drop-shadow(0px 3px 4px rgba(0,0.5));
}

.arrow {
  height: 30px;
  display:inline;
  position:relative;
}

.content{
  display:inline-block;
  padding: 0.7em 1em 0.5em;
  min-width: 10em;
  background: linear-gradient(270deg,#B07537 0,#F0B971 100%);
  position:relative;
  color: white;
  font-weight: 500;
}

.box:before,.box:after,.arrow:before,.arrow:after {
  content:'';
  position:absolute;
  border-style:solid;
}

.arrow:before {
  top: -0.2em;
  bottom: 0;
  left:-1.85em;
  margin: auto;
  border-width: 1.4em 1em 1.4em 1.15em;
  border-color: #fccc4f #fccc4f #fccc4f transparent;
  z-index:-1;
}

.arrow:after {
  left:-1.5em;
  margin: auto;
  border-width: 1.2em 1em 1.2em 1em;
  border-color: #F0B971 #F0B971 #F0B971 transparent ;
  z-index:-1;
}

.box:before{
  top: -0.15em;
  bottom: -0.15em;
  left:0;
  right: 0;
  margin: auto;
  border-width: 1.4em 1em 1.4em 1.15em;
  border-color: #fccc4f #fccc4f #fccc4f transparent;
  z-index:-1;
}

.box:after{
  bottom: -.6em; 
  right:0;
  border-width: 0 0 .4em .7em;
  border-color:  gray transparent transparent gray ;
}

.text {
  margin-left: -2em;
  line-height: 1;
  letter-spacing: 2px;
  font-weight: bold;
}

/* .text:before{
  top:100%; left:0;
  border-width: .5em 2em 0 0;
  border-color: #FC9544 transparent transparent transparent;
} */
<div class="box">
  <div class="arrow"></div>
  <div class="content">
    <span class="text">Text</span>
    </div>
</div>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。