这是我最好的尝试。
我在 Chrome 中纠正了一个小问题;但我真的不知道它为什么会起作用。
CCS 是
.test {
display: table-row;
white-space: nowrap;
line-height: 0px;
}
.test:before,
.test:after {
border-color: transparent;
border-top: solid black 1px;
border-left: solid transparent 1px;
border-bottom: solid rgba(0,0,0,0.01) 11px;
border-right: solid transparent 1px;
content: "";
display: table-cell;
width: 50%;
}
.test:before {
border-right: solid 30px transparent;
}
.test:after {
border-left: solid 30px transparent;
}
我正在使用边框来显示黑线,并将其放置在适当的位置,我已将表格的高度降低到 0。
在小提琴中,我保留了您的原始演示,以便您可以并排比较。
现在,奇怪的部分。将边框底部的 rgba(0,0,0,0.01) 更改为 rgba(0,0,0,0.001),它会中断(至少在 Chrome 中)。
我真的很想明白这...
新答案
以上所有假设要求具有透明样式(即,可以设置可以通过 h1 看到的背景。如果不是这种情况,还有另一种可能的解决方案,使用 box-阴影而不是渐变背景:
.test {
display: table-row;
white-space: nowrap;
}
.test:before,
.test:after {
border: solid white 10px;
content: "";
display: table-cell;
width: 50%;
height: 10px;
line-height: 10px;
box-shadow: inset 0px 5px white, inset 0px 6px black;
}
.test:before {
border-right-width: 10px;
border-left-width: 1px;
}
.test:after {
border-left-width: 10px;
border-right-width: 1px;
}