首先,如果誤導了我的標題,我很抱歉。其實,我不知道這個更好的標題,這就是爲什麼我這樣給它。如果任何人都可以爲這個解決方案獲得更好的稱號,請幫助我改變。如何修復和重新安排固定位置div
我的問題是,我的一位Web開發人員創建了固定div位置的頁面,並正確放置了所有div。現在問題出現了,我想將所有內容都轉移到瀏覽器的中心。我試圖用整個div進行包裝並移動到中心位置。但它不會因爲位置而移動:固定,與左對齊。我不想計算每個左邊的位置並移動它,因爲它太多了。我怎樣才能把整個事情包裝起來,並通過更好的方式將其轉移到中心?我包含了一些代碼來了解我在說什麼。如果我的問題不是真的有幫助,請告訴我,我會解釋更多。
HTML
<div id="apDiv1"><img src="images/bg.png" /></div>
<div id="apDiv2"><img src="images/border1.png" /></div>
<div id="apDiv3"><img src="images/border2.png" width="130" height="450" /></div>
<div id="apDiv4"><img src="images/bar1.png" width="128" height="450" /></div>
<div id="apDiv5"><img src="images/bar2.jpg" width="110" height="164" /></div>
<div id="apDiv6"><img src="images/bar3.jpg" width="110" height="164" /></div>
<div id="apDiv7"><img src="images/button1.jpg" width="110" height="164" /></div>
<div id="apDiv8"><img src="images/button2.jpg" width="110" height="164" /></div>
<div id="apDiv9"><img src="images/button3.jpg" width="286" height="23" /></div>
<div id="apDiv10"><img src="images/redbar.jpg" width="286" height="23" /></div>
<div id="apDiv11"><img src="images/redbar.jpg" width="286" height="23" /></div>
<div id="apDiv12"><img src="images/redbar.jpg" width="286" height="23" /></div>
<div id="apDiv13"><img src="images/gobtn.png" /></div>
<div id="apDiv14"><img src="images/submitbtn.png" /></div>
<div id="apDiv15"><img src="images/submitbtn3.png" /></div>
<div id="apDiv16"><img src="images/downloadbtn.png" /></div>
CSS
#apDiv1 {
position:fixed;
width:200px;
height:115px;
z-index:-1;
left:120px;
}
#apDiv2 {
position:fixed;
width:200px;
height:115px;
z-index:2;
left: 380px;
top: 108px;
}
#apDiv3 {
position:fixed;
width:200px;
height:115px;
z-index:2;
left: 248px;
top: 108px;
}
#apDiv4 {
position:fixed;
width:200px;
height:115px;
z-index:2;
left: 120px;
top: 108px;
}
#apDiv5 {
position:fixed;
width:200px;
height:115px;
z-index:2;
left: 380px;
top: 195px;
}
#apDiv6 {
position:fixed;
width:200px;
height:115px;
z-index:2;
left: 677px;
top: 196px;
}
#apDiv7 {
position:fixed;
width:200px;
height:115px;
z-index:2;
left: 380px;
top: 387px;
}
#apDiv8 {
position:fixed;
width:200px;
height:115px;
z-index:2;
left: 677px;
top: 387px;
}
#apDiv9 {
position:fixed;
width:200px;
height:115px;
z-index:1;
left: 380px;
top: 171px;
}
#apDiv10 {
position:fixed;
width:200px;
height:115px;
z-index:1;
left: 677px;
top: 171px;
}
#apDiv11 {
position:fixed;
width:200px;
height:115px;
z-index:1;
left: 677px;
top: 362px;
}
#apDiv12 {
position:fixed;
width:200px;
height:115px;
z-index:1;
left: 380px;
top: 362px;
}
#apDiv13 {
position:fixed;
width:200px;
height:115px;
z-index:1;
left: 579px;
top: 346px;
}
#apDiv14 {
position:fixed;
width:200px;
height:115px;
z-index:1;
left: 875px;
top: 346px;
}
#apDiv15 {
position:fixed;
width:200px;
height:115px;
z-index:1;
left: 579px;
top: 538px;
}
#apDiv16 {
position:fixed;
width:200px;
height:115px;
z-index:1;
left: 875px;
top: 538px;
}
謝謝大家。 :)
是啊,這是其他開發人員的工作。所以我可以知道創建佈局時使用div的最佳方式是什麼?作爲一個絕對還是相對的位置? – knightrider 2011-03-25 06:26:53
這樣做的正確方法是使他相對包裝div和所有子div div絕對。這樣子div將被定位在包裝器而不是瀏覽器窗口。沿着這條路線,可以靈活地重新包裝包裝並將其中的所有物品進行相應的重新定位。 – Hussein 2011-03-25 06:33:25
因此,如果我將創建包含相對位置的包裝div並將所有這些子div更改爲絕對內部相對,它會正常工作嗎? – knightrider 2011-03-25 06:38:05