2009-07-16 73 views
1

我想創建一個div,從左邊開始200px,並延伸到右邊的頁面邊緣但不超出。現在以100%的寬度將頁面向右延伸200px。沒有寬度,它仍然超出200px。靈活寬度的縮進div

任何想法如何使這項工作?

#MsgBanner{ 
    position:relative; 
    background-color:#333; 
    top:60px; 
    height:30px; 
    z-index:14; 
    width:100%; 
    left:200px; 
} 

回答

3

你可以使用:

#MsgBanner { 
width: auto; 
margin-left: 200px; 
} 
+0

這很好。謝謝。 – chrishomer 2009-07-16 20:46:09

+0

不客氣,很高興有幫助=] – 2009-07-16 21:12:40

0
#MsgBanner{ position:relative; background-color:#333; top:60px; height:30px; z-index:14; width:100%; margin-left:200px;} 

我認爲,所有你需要做的是設置margin在左邊200像素代替。

+0

寬度必須是自動的。這仍然延伸到屏幕之外。 – chrishomer 2009-07-16 20:47:43

2

據我所知,這是不可能的,而不在CSS3引入的鈣()函數。

#MsgBanner{ 
    position:relative; 
    background-color:#333; 
    top:60px; 
    height:30px; 
    z-index:14; 
    width:calc(100% - 200px); 
    left:200px; 
} 

上面會解決CSS3中的問題,但並不是所有的瀏覽器都支持它。