<分区>
CSS 可以实现这样的功能吗?我已经尝试通过伪元素之前/之后,虽然我可以获得一些适用于纯色的东西,但我很难想出一种透明的方法。
有什么建议吗?
标签 html css css-shapes
<分区>
CSS 可以实现这样的功能吗?我已经尝试通过伪元素之前/之后,虽然我可以获得一些适用于纯色的东西,但我很难想出一种透明的方法。
有什么建议吗?
最佳答案
如果您不需要每个元素周围的黑色边框(如发布的图片所示),您仍然可以通过 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>
但是,如果您需要为每个元素添加边框,有两种选择:
drop-shadow()
filter伪造边界 - Example Here (Webkit/Firefox35+ 支持)。border
将不被使用并可供以后使用(IE9+ 也支持)。关于html - CSS重叠透明箭头元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26602577/