2012-05-02 41 views
0

我試圖讓3D色帶盒CSS3,但得到的一些問題,使3D色帶盒我怎樣才能讓這個純CSS 用最少的代碼。如何創建CSS

這裏是我試圖使圖像.....

enter image description here

感謝

回答

7

這裏有一個辦法做到這一點,相當小的標記。 :before:after僞元素需要IE 8+,如果你需要支持較低的(IE6/7),你可以使用兩個額外的<div>元素爲三角形的角落。

example jsfiddle

HTML:

<div id="box"> 
    <div id="ribbon">3d Text and rounded corner sample</div> 
</div>​ 

CSS:

#box { 
    position:relative; 
    background:gray; 
    width:400px; 
    height:300px; 
    margin:20px 45px; 
} 
#ribbon { 
    position:absolute; 
    top:15px; 
    left:-20px; 
    width:360px; 
    height:55px; 
    background:#ff2702; 
    color:white; 
    padding:20px 40px; 
    font-size:24px; 
    font-weight:bold; 
    border-radius:5px 5px 0 0; 
    box-shadow:0 0 8px #333; 
    text-shadow:0 0 8px #000; 
} 
#ribbon:before { 
    content:''; 
    position:absolute; 
    bottom:-20px; 
    left:0; 
    border-top:solid 10px #ff2702; 
    border-right:solid 10px #ff2702; 
    border-bottom:solid 10px transparent; 
    border-left:solid 10px transparent; 
} 
#ribbon:after { 
    content:''; 
    position:absolute; 
    bottom:-20px; 
    right:0; 
    border-top:solid 10px #ff2702; 
    border-right:solid 10px transparent; 
    border-bottom:solid 10px transparent; 
    border-left:solid 10px #ff2702; 
} 
​ 
+0

哎@mdmullix您anwser是正確的,但你這就是定義的所有四個邊框屬性爲什麼在你的箭頭邊境差一些檢查我如何我做了http://jsfiddle.net/EKs3a/30/並將其與你的答案進行比較,你會知道我在說什麼反正謝謝你的回答.... –

+0

嗨,mdmullinax,我怎樣才能讓角落圓而不是平的?你能重新編碼那個圓角的小提琴嗎?謝謝 – jeewan

+1

@soflover嘗試'#box {border-radius:5px}' – MikeM