2013-07-27 28 views
0

我想要創建以下div邊框: enter image description here 我對綠色邊框部分進行了排序,但不是沿着頂部的紅色線條。有任何想法嗎?如何在CSS中創建三重div邊框

到目前爲止的代碼:

#myborder { 
border: 4px solid green; 
} 
+0

如果我理解正確 - 你不想整個頂部邊框是紅色的 - 但是綠色 - 紅色 - 綠色,對吧? –

+0

是的,正確的感謝 – alias51

回答

4

使用這個CSS http://jsfiddle.net/PESHk/3

#myborder { 
    box-shadow: 0 0 0 4px green, 0 0 0 4px green inset; 
    border-top:2px solid red; 
    padding:8px; 
} 
+0

nope - 它會用紅色部分做所有4面 - 不僅頂部 –

+0

Upvote。這個有關鍵。 –

+0

如果您僅使用邊框頂部而不是使用此邊框頂部,則其所有側面都會打開您的眼睛:2px純紅色; – Hushme

2

上Hushme的回答工作:通過使用::beforehttp://jsfiddle.net/PESHk/2/

#myborder { 
    box-shadow: 0 0 0 4px green, 0 0 0 4px green inset; 
    border-top: 2px solid red; 
    padding: 8px; 
} 

而且here

#myborder { 
    box-shadow: 0px 4px 15px rgba(0,0,0,0.15); 
    border: 8px solid green; 
    border-top: 0; 
    padding: 16px 8px 8px 8px; 
    position: relative; 
} 

#myborder::before { 
    width: 100%; 
    background: red; 
    height: 2px; 
    border: 4px solid green; 
    content: ""; 
    display: block; 
    position: absolute; 
    left: 0; 
    top: 0; 
}