2011-12-13 99 views
2

我有一個固定並居中在頁面上的菜單有問題。無論用戶的屏幕尺寸如何,我都希望整個菜單(3個背景圖像)覆蓋整個頁面寬度。固定菜單,重複-x左邊,重複-x右邊

原單圖片 (圖片1:寬度1px的,高度76px;) (圖片2:寬度1135px,高度76px;) (圖片3:寬度1px的,高度76px;)

CSS更改後我希望這些成爲 (圖片1:寬度392,5px,高度76px;) (圖片2:寬度1135px,高度76px;) (圖片3:寬度392,5px,高度76px ;)

<div style="position:fixed; width:100%; height:76px;"> 
    <div> Picture 1 </div> <-- repeat-x on the left side 
    <div> Picture 2 , center of the page , no-repeat</div> 
    <div> Picture 3</div> <-- repeat-x on the right side 
</div> 

我想在圖片1和3上設置repeat-x,但不知道寬度。我可以用jQuery修復它,但沒有一種方法在CSS中?

+0

我建議你發佈你想要的結果的圖像,會有很多比較容易回答 – ptriek

+0

你是什麼意思「CSS更改後」?你是否期待點擊,懸停等? –

+0

沒有。我不想「重複-x」來填充網站的寬度。 – Plexus81

回答

2

更新了透明中心圖像見,http://jsfiddle.net/QEPX4/5/show/

HTML

<div class="TriHeader"> 
    <div class="left"><div></div></div> 
    <div class="center"></div> 
    <div class="right"><div></div></div> 
</div> 

CSS(代表)

.TriHeader { 
    position:fixed; 
    width:100%; 
    height:76px; 
} 

.TriHeader div { 
    height: 76px; 
    position: absolute; 
} 

.TriHeader .left { 
    left: 0; 
    right: 50%; 
    z-index: 0; 
} 

.TriHeader .left div { 
    background: url(repeatingLeftImage.png) top left repeat-x; 
    right: 567.5px; 
    left: 0; 
    top: 0; 
} 

.TriHeader .center { 
    background: url(nonrepeatingCenterImage.png) top left no-repeat; 
    width: 1135px; 
    left: 50%; 
    margin-left: -567.5px; /*ideally, the image would be an even number */ 
    z-index: 1; 
} 

.TriHeader .right { 
    left: 50%; 
    right: 0; 
    z-index: 0; 
} 

.TriHeader .right div { 
    background: url(repeatingRightImage.png) top left repeat-x; 
    left: 567.5px; 
    right: 0; 
    top: 0; 
} 

如果你不關心IE7,那麼你就可以消除在左側和右側嵌套div元素並用僞替換css O單元選擇,如:

.TriHeader .right:before { 
    content: ''; 
    display: block; 
    position: absolute; 
    background: url(repeatingRightImage.png) top left repeat-x; 
    left: 567.5px; 
    right: 0; 
    top: 0; 
} 
+0

不幸的是,中間的圖片是透明的。這是接近解決方案.. – Plexus81

+0

@ Plexus81 - 我已更新,以允許透明的中心圖像。 – ScottS

+0

謝謝!它的工作原理:)認爲奇怪的是,CSS不支持這個開箱即用,就像repeat-x right/left。 – Plexus81