2012-12-19 26 views
7

有人可以告訴我的CSS代碼或指向我一個關於如何實現這種效果的教程看到所有的時間。 以下是我在談論的形象:如何製作一個標題欄摺疊在網頁上css

enter image description here

注:我知道如何與絕對我只需要知道他們是怎麼拉的效果關閉定位。

+0

這是一個關於定位或有關「色帶旗幟效應」的問題? – PeeHaa

回答

6

如果色帶是問題,然後使用邊界空(0尺寸)元素(您可以與:after僞元素添加)上..

的Html

<div id="content"> 
    <div id="ribbon"></div> 
</div> 

CSS

#content{ 
    background-color:#77c; 
    width:300px; 
    height:200px; 
    position:relative; 
} 
#ribbon{ 
    position:absolute; 
    width:80px; 
    height:30px; 
    right:-20px; 
    top:50px; 
    background-color:#999; 
} 
#ribbon:after{ 
    content:''; 
    width:0; 
    height:0; 

    border-color: transparent transparent #666 #666; 
    border-style:solid; 
    border-width:5px 10px; 

    position:absolute; 
    right:0; 
    top:-10px; 
} 

演示在http://jsfiddle.net/gaby/zJPhy/

+0

謝謝加比,這是完美的,你可以給我一個左邊的例子。 –

+1

@JohnFloyd,請參閱http://jsfiddle.net/gaby/zJPhy/2/只需重新排列邊框顏色並將其正確定位即可。 –

+0

感謝您的時間兄弟 –

1

這可能是相對定位或絕對 - 它可以做兩種方式:

#item { 
    position: relative; 
    right: -10px; /* moves it 10px to the right */ 
} 

或者絕對:

#item { 
    position: absolute: 
    top: 20px; /* 20px from the top */ 
    right: -20px; /* 20px off the right edge */ 
} 

注意,絕對定位的元素將根據視口,如果定位他們沒有定位的祖先。

摺疊部分可以使用僞元素:before:after上的邊界來完成。

演示:http://jsfiddle.net/MaepP/2/