create ribbon with css

不羁的心 提交于 2019-12-02 02:29:39

this will have to be adapted to your needs, but something using pseudo elements would make this possible:

.box{
  height:300px;
  width:300px;
  box-shadow:inset 0 0 15px #222;
  position:relative;
  margin:0 auto;
  background:gray;
  }

.active{
  position:absolute;
  top:30px;
  left:-5%;
  height:30px;
  width:105%;
  background:tomato;
  border-radius: 5px 0 0 0;
  }
.active:before{
  content:"";
  position:absolute;
  height:16px;
  top:5px;
  left:0;
  width:100%;
  border-top:2px dashed red;
  border-bottom:2px dashed red;
  }
.active:after{
  content:"";
  position:absolute;
  right:-10px;
  height:20px;
  width:20px;
  top:5px;
  background:tomato;
  border-radius: 0 5px 0 0;
  transform:rotate(45deg);  
  }
.active a{
  position:absolute;
  top:0;
  left:0;
  height:100%;
  width:100%;
  text-align:center;
  display:inline-block;
  text-decoration:none;
  line-height:30px;
  }
.active a:after{
  content:"";
  position:absolute;
  bottom:-15px;
  left:6px;
  height:30px;
  width:30px;
  background:darkred;;
  transform:rotate(45deg);  
  z-index:-2;
  }
<div class="box">

<div class="active">
  <a href="#">some text</a>
  </div>
</div>

note

the transform property will require prefixes as well.

it's real with CSS3.

maybe like this:) but you need to customize.

html:

* {
  box-sizing: border-box;
}
.container {
  width: 80%;
  max-width: 1000px;
  height: 80px;
  margin: 40px auto;
  position: relative;
}
.one > div {
  height: 50px;
}
.main {
  background: #0fadc0;
  position: relative;
  display: block;
  width: 90%;
  left: 50%;
  top: 0;
  padding: 5px;
  margin-left: -45%;
  z-index: 10;
}
.main > div {
  border: 1px dashed #fff;
  border-color: rgba(255, 255, 255, 0.5);
  height: 40px;
}
.bk {
  background: #1199a9;
  position: absolute;
  width: 8%;
  top: 12px;
}
.bk.l {
  left: 0;
}
.bk.r {
  right: 0;
}
.skew {
  position: absolute;
  background: #0c7582;
  width: 3%;
  top: 6px;
  z-index: 5;
}
.skew.l {
  left: 5%;
  transform: skew(00deg, 20deg);
}
.skew.r {
  right: 5%;
  transform: skew(00deg, -20deg);
}
.bk.l > div {
  left: -30px;
}
.bk.r > div {
  right: -30px;
}
.arrow {
  height: 25px !important;
  position: absolute;
  z-index: 2;
  width: 0;
  height: 0;
}
.arrow.top {
  top: 0px;
  border-top: 0px solid transparent;
  border-bottom: 25px solid transparent;
  border-right: 30px solid #1199a9;
}
.arrow.bottom {
  top: 25px;
  border-top: 25px solid transparent;
  border-bottom: 0px solid transparent;
  border-right: 30px solid #1199a9;
}
.r .bottom {
  border-top: 25px solid transparent;
  border-bottom: 0px solid transparent;
  border-left: 30px solid #1199a9;
  border-right: none;
}
.r .top {
  border-bottom: 25px solid transparent;
  border-top: 0px solid transparent;
  border-left: 30px solid #1199a9;
  border-right: none;
}
@media all and (max-width: 1020px) {
  .skew.l {
    left: 5%;
    transform: skew(00deg, 25deg);
  }
  .skew.r {
    right: 5%;
    transform: skew(00deg, -25deg);
  }
}
@media all and (max-width: 680px) {
  .skew.l {
    left: 5%;
    transform: skew(00deg, 30deg);
  }
  .skew.r {
    right: 5%;
    transform: skew(00deg, -30deg);
  }
}
@media all and (max-width: 460px) {
  .skew.l {
    left: 5%;
    transform: skew(00deg, 40deg);
  }
  .skew.r {
    right: 5%;
    transform: skew(00deg, -40deg);
  }
}
<!-- RIBBON 1 -->
<div class="container one">
  <div class="bk l">
    <div class="arrow top"></div>
    <div class="arrow bottom"></div>
  </div>
  <div class="skew l"></div>

  <div class="main">
    <div></div>
  </div>

  <div class="skew r"></div>

  <div class="bk r">
    <div class="arrow top"></div>
    <div class="arrow bottom"></div>
  </div>

</div>

https://jsfiddle.net/5pu4rqr8/

this is a pure copy/paste from @willpaige's CodePen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!