CSS重叠透明箭头元素

时间:2014-10-28 07:04:05

标签: html css css-shapes

CSS可以这样吗?我在伪元素之前/之后尝试过,虽然我可以得到一些可用于纯色的东西,但是我无法想出一种透明度的方法。

http://puu.sh/ctOL6/875fb5db8f.png

有什么建议吗?

2 个答案:

答案 0 :(得分:4)

如果您不需要每个项目周围的黑色边框(如发布的图片中所示),您仍然可以按border创建所需的形状,如下所示:

.timeline-unit:before, .timeline-unit:after {
    top: 0;
    border: solid transparent;
    border-width: 1.65em;
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none;
}

.timeline-unit:after {
    content: " ";
    left: 100%;
    border-left-color: rgba(51, 51, 51, 0.8);
}

.timeline-unit {
    position: relative;
    display: inline-block;
    background: rgba(51,51,51,.8);
    padding: 1em;
    line-height: 1.25em;
    color: #FFF;
}

.timeline-unit:before { content: none; }

.timeline-unit + .timeline-unit:before {
    content: " ";
    border-color: rgba(51, 51, 51, 0.8);
    border-left-color: transparent;
    border-right: 0;
    right: 100%;
}

.timeline-unit + .timeline-unit {
    margin-left: 2em;
}

/**************  D E M O  **************/

body {
  background: red;
    
  -webkit-animation: bgcolor 4s linear 0s infinite alternate;
     -moz-animation: bgcolor 4s linear 0s infinite alternate;
       -o-animation: bgcolor 4s linear 0s infinite alternate;
          animation: bgcolor 4s linear 0s infinite alternate;
}

@-webkit-keyframes bgcolor { from { background: red; } to { background: green; }  }
   @-moz-keyframes bgcolor { from { background: red; } to { background: green; }  }
     @-o-keyframes bgcolor { from { background: red; } to { background: green; }  }
        @keyframes bgcolor { from { background: red; } to { background: green; }  }
<div class="timeline-unit"> Timeline 1 </div>
<div class="timeline-unit"> Timeline 2 </div>
<div class="timeline-unit"> Timeline 3 </div>

但是,如果您需要在每个项目上添加边框,则有两个选项:

答案 1 :(得分:2)

我希望这可行。

&#13;
&#13;
li {
  display: inline-block;
  background: none repeat scroll 0 0 #e6e6e6;
  position: relative;
  list-style: none outside none;
  margin-right: 5px;
  line-height: 18px;
  padding: 12px 17px 10px 30px;
}
li:first-child {
  padding-left: 12px;
}
li:first-child:before {
  border: 0 none;
}
li:before {
  content:"";
  position: absolute;
  top: 0;
  height: 0;
  border-left: 20px solid white;
  border-bottom: 20px inset transparent;
  border-top: 20px inset transparent;
  width: 0;
  left: 0;
}
li:after {
  content:"";
  height: 0;
  border-left: 20px solid #e6e6e6;
  right: -20px;
  border-top: 20px inset transparent;
  border-bottom: 20px inset transparent;
  z-index: 2;
  width: 0;
  position: absolute;
  top: 0;
}
&#13;
<ul>
  <li>daTA1</li>
  <li>daTA2</li>
  <li>daTA3</li>
  <li>daTA4</li>
</ul>
&#13;
&#13;
&#13;     

<强>输出

enter image description here