2014-10-28 107 views
4

是這樣的CSS可能嗎?我曾經嘗試通過僞元素之前/之後,雖然我可以得到一些工作的純色,我有麻煩想辦法做到透明。CSS重疊的透明箭頭元素

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

有什麼建議?

+1

你能告訴我們你的代碼嗎? - codepen.io或jsfiddle.net。謝謝,那麼我們可以幫助你更好。 – 2014-10-28 07:05:38

+1

請寫下您的代碼,並詳細說明您所做的事情以及您的問題。 – 2014-10-28 07:09:20

+0

這更多的是一個理論問題。任何先前的代碼嘗試都不是靠近解決方案。這是我得到的最接近的:http://codepen.io/anon/pen/pmoni – user2083984 2014-10-28 07:18:51

回答

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

+1非常好用的EM單位:) – 2014-10-28 08:53:11

+1

偉大的,聰明的解決方案,以解決複雜的問題。非常感謝! – user2083984 2014-10-28 16:49:21

+1

非常聰明和不錯的演示(帶動畫):) – Harry 2014-10-29 11:51:00

2

我希望這可以工作。

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>

輸出

enter image description here

+0

感謝您提供可能的解決方案,但這受到透明度問題的困擾。邊框分隔必須是透明的,以便背景仍然可見。這是主要問題 - 我無法使用純色進行嵌入邊框分隔。 – user2083984 2014-10-28 07:22:48

+0

@ user2083984如果這是您的要求,那麼實現起來相當困難。我們依靠僞元素重疊來「阻擋」元素,但如果它們是透明的,他們不能這樣做。 – 2014-10-28 07:24:48

+0

@harley_woop是的,我同意。我對CSS非常精通,不能想出辦法做到這一點(至少可以實現這一點)。我不認爲使用psuedo元素完全可以工作,但我甚至不能想到實現所需功能的另一種方法。 – user2083984 2014-10-28 07:33:19