2013-04-16 120 views
1

我試圖讓3個靈活的圖像在水平方向排隊,並保持其具有靈活的背景及其靈活的div容器的範圍內,3靈活父DIV中靈活的div

容器的背景和3張照片應該全部保持彼此的位置關係,以便它們始終位於彼此之上。它們應該隨瀏覽器窗口的大小而變得越來越小,但寬度不超過800像素。

我遇到的問題是左側的背景和頁腳大滿貫,按鈕divs正確。

My JSFIDDLE

HTML:

<div id="container"> 
<div id="footer"> 
    <div id="left"> 
     <input type="image" name="MyLeftButton" id="MyLeftButton" class="imgstretch" src="Images/MyLeftImage.png" style="border-width:0px;"> 
    </div> 
    <div id="middle"> 
     <input type="image" name="MyMiddleButton" id="MyMiddleButton" class="imgstretch" src="Images/MyMiddleImage.png" style="border-width:0px;"> 
    </div> 
    <div id="right"> 
     <input type="image" name="MyRightButton" id="MyRightButton" class="imgstretch" src="Images/MyRightImage.png" style="border-width:0px;"> 
    </div> 
    </div> 
</div> 

CSS:

#container { 
margin: 0em auto 0em auto; 
width: 100%; 
max-width: 800px; 
} 

#footer { 
width: 100%; 
max-width: 800px; 
max-height: 80px; 
float: left; 
text-align: center; 
position: fixed; 
bottom: 0em; 
background-color: #009FC1; 
} 

#left { 
float: left; 
max-height: 80px; 
max-width: 294px; 
width: 36%; 
margin-left: 20px; 
display: inline-block; 
background-color: #CCCCCC; 
} 

#middle { 
max-height: 80px; 
width: 25%; 
float: left; 
max-width: 202px; 
display: inline-block; 
background-color: #889FC1; 
} 

#right { 
max-height: 80px; 
max-width: 294px; 
width: 36%; 
float: left; 
display: inline-block; 
background-color: #9999DD; 
} 

.imgstretch { 
width:100%; 
} 
+2

CSS問題需要* generated * HTML,ASP模板代碼對我們來說沒用。 – cimmanon

+0

對此我很抱歉。我澄清了我的代碼幷包含JSFIDDLE。 – fred1234

回答

2

你必須去的一對夫婦的事情。

1)頁腳設置爲固定位置,這會使其忽略父元素並將其自身固定到窗口。我不知道這是否是您佈局的問題,但需要注意的地方。

2)你已經在已經有一個定義類的元素上設置了內聯樣式。似乎沒有必要。 3)您的尺寸計算結果與您的%和px相關。 36%應該是(0.36 * 800),它會以288像素,而不是294像素,然後再加上20像素的邊距。

我已經分叉你的小提琴。 http://jsfiddle.net/ZBJPF/8/

html { 
    margin: 0; 
    padding: 0; 
} 
body { 
    margin: 0; 
    padding: 0; 
} 
#container { 
    margin: 0 auto; 
    width: 100%; 
    max-width: 800px; 
} 
#footer { 
    width: 100%; 
    max-width: 780px; 
    max-height: 80px; 
    margin: 0 auto; 
    padding-left: 20px; 
    text-align: center; 
    position: fixed; 
    bottom: 0; 
    background-color: #009FC1; 
} 
.footer-element-lg { 
    float: left; 
    width: 36%; 
    max-width: 280px; 
    position: relative; 
} 
.footer-element-sm { 
    float: left; 
    width: 28%; 
    max-width: 220px; 
    position: relative; 
} 
#left { 
    background-color: #CCCCCC; 
} 
#middle { 
    background-color: #889FC1; 
} 
#right { 
    background-color: #9999DD; 
} 
.imgstretch { 
    width:100%; 
    border: none; 
} 

<div id="container"> 
    <div id="footer"> 
     <div id="left" class="footer-element-lg"> 
      <input type="image" name="MyLeftButton" id="MyLeftButton" class="imgstretch" src="Images/MyLeftImage.png"> 
     </div> 
     <div id="middle" class="footer-element-sm"> 
      <input type="image" name="MyMiddleButton" id="MyMiddleButton" class="imgstretch" src="Images/MyMiddleImage.png"> 
     </div> 
     <div id="right" class="footer-element-lg"> 
      <input type="image" name="MyRightButton" id="MyRightButton" class="imgstretch" src="Images/MyRightImage.png"> 
     </div> 
    </div> 
</div> 

我除去20像素的裕度和取得的間距爲20像素的填充的連續性的緣故。

+0

謝謝。我很困難,因爲圖像的尺寸沒有切成正確的百分比,我需要將頁腳始終粘貼在窗口的底部。我會在幾分鐘內嘗試。 – fred1234

+0

您可以嘗試將這種技術添加到這些元素以獲得完整的拉伸背景。 http://css-tricks.com/perfect-full-page-background-image/該文章舉例說明了整頁BG,但它適用於任何要設置它的元素。 – Plummer

+0

嗯,我試過上面的代碼和它做同樣的事情。如果它有助於我的原始圖像尺寸是 – fred1234