回答
如果你不需要圍繞每個項目的黑色邊框(如可以在發佈的圖像中可以看到),你仍然可通過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中/ firefox應支持+ )。 - 使用CSS transforms爲了創建CSS形狀,因此
border
將被閒置並可用於以後的使用(在IE9 +中也支持)。
+1非常好用的EM單位:) – 2014-10-28 08:53:11
偉大的,聰明的解決方案,以解決複雜的問題。非常感謝! – user2083984 2014-10-28 16:49:21
非常聰明和不錯的演示(帶動畫):) – Harry 2014-10-29 11:51:00
我希望這可以工作。
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;
}
<ul>
<li>daTA1</li>
<li>daTA2</li>
<li>daTA3</li>
<li>daTA4</li>
</ul>
輸出
感謝您提供可能的解決方案,但這受到透明度問題的困擾。邊框分隔必須是透明的,以便背景仍然可見。這是主要問題 - 我無法使用純色進行嵌入邊框分隔。 – user2083984 2014-10-28 07:22:48
@ user2083984如果這是您的要求,那麼實現起來相當困難。我們依靠僞元素重疊來「阻擋」元素,但如果它們是透明的,他們不能這樣做。 – 2014-10-28 07:24:48
@harley_woop是的,我同意。我對CSS非常精通,不能想出辦法做到這一點(至少可以實現這一點)。我不認爲使用psuedo元素完全可以工作,但我甚至不能想到實現所需功能的另一種方法。 – user2083984 2014-10-28 07:33:19
- 1. 重疊部分透明元素的不透明度
- 2. 具有不透明度的CSS元素與html5視頻重疊
- 3. 重疊具有不同不透明度的CSS元素
- 4. CSS箭頭不透明度轉換
- 5. CSS只有透明箭頭後段
- 6. 使用漸變重疊CSS 3箭頭
- 7. 重疊CSS元素
- 8. 創建透明箭頭
- 9. 如何使一個透明元素與其他元素重疊?
- 10. QML - 堆疊元素的不透明度
- 11. CSS位置箭頭元素 - jquery循環
- 12. 箭頭重疊連接
- 13. D3.js - 重疊箭頭
- 14. CSS菜單重疊元素
- 15. 重疊元素 - HTML,CSS
- 16. CSS:重疊元素圓角
- 17. 帶箭頭的透明屏幕
- 18. 帶陰影的透明箭頭內部
- 19. 左邊的透明箭頭內部
- 20. 完全靈活的HTML/CSS「透明」導航箭頭(見例)
- 21. 重疊的透明背景
- 22. iOS上Safari上的<select>元素上的不透明箭頭和樣式
- 23. 保險絲重疊與透明背景和框陰影元素
- 24. 導航條帶透明箭頭指針
- 25. WPF中透明的不透明元素
- 26. CSS透明度,如何在透明容器元素
- 27. 半透明父元素的透明子元素?
- 28. 不透明元素中的透明元素
- 29. 父元素透明的HTML元素不會變得不透明
- 30. 不透明元素上的不透明元素
你能告訴我們你的代碼嗎? - codepen.io或jsfiddle.net。謝謝,那麼我們可以幫助你更好。 – 2014-10-28 07:05:38
請寫下您的代碼,並詳細說明您所做的事情以及您的問題。 – 2014-10-28 07:09:20
這更多的是一個理論問題。任何先前的代碼嘗試都不是靠近解決方案。這是我得到的最接近的:http://codepen.io/anon/pen/pmoni – user2083984 2014-10-28 07:18:51