2012-01-27 85 views
1

我以爲我得到了這個問題,然後我遇到了一個我無法弄清的問題。Div高度爲100%,要麼不夠高,要麼太高

如果我將包裝高度設置爲auto,它會下降到內容的底部並停止,如果內容不像窗口那樣高,則會看到它背後的背景。
如果我將包裝設置爲100%this發生。

當屏幕最大化時,頁面高於窗口高度,並強制頁面滾動不必要。 請參閱this

當窗口較小時,背景會在內容後面爬行。
我不知道什麼頁面滾動時,它不需要,當窗口收縮我想包裝的背景仍然覆蓋內容。 我該如何解決這個問題/我沒有看到什麼?
感謝

編輯:

<div id="xwraper"> 
<div id="wraper"> 

    <br class="cl cr" /> 
    <div id="imgholder"> 
     <div class="slider"> 
          <ul> 
           <li rel="1"> 
            <img src="id_tags_1.png" width="510" height="340" alt="&nbsp;" /> 
            <h4>&nbsp;</h4> 
           </li> 
           <li rel="2"> 

            <img src="id_tags_2.png" width="510" height="340" alt="&nbsp;" /> 
            <h4>&nbsp;</h4> 
           </li> 
           <li rel="3"> 
            <img src="id_tags_3.png" width="510" height="340" alt="&nbsp;" /> 
            <h4>&nbsp;</h4> 
           </li> 
           <li rel="4"> 
            <img src="id_tags_4.png" width="510" height="340" alt="&nbsp;" /> 

            <h4>&nbsp;</h4> 
           </li> 
          </ul> 
          <div class="clear controls"> 
           <img src="../../img/white-arrow-left.png" width="10" height="13" alt="&lt;" class="prev" /> 
           <span class="pages"> 
            <img src="../../img/blank.gif" width="13" height="14" alt="&nbsp;" class="number hide selected 1" /> 
            <img src="../../img/blank.gif" width="13" height="14" alt="&nbsp;" class="number hide 2" /> 
            <img src="../../img/blank.gif" width="13" height="14" alt="&nbsp;" class="number hide 3" /> 

            <img src="../../img/blank.gif" width="13" height="14" alt="&nbsp;" class="number hide 4" /> 
           </span> 
           <img src="../../img/white-arrow-right.png" width="10" height="13" alt="&gt;" class="next" /> 
          </div> 
         </div>  </div> 
    <div id="desc"> 
     <p>Identification Tags are a versatile, cost effective way to get your marketing message out. Used by travelers, sports teams, schools, health clubs, athletes and organizations, these tags are durable and each comes with it's own clear lanyard.</p> 
     <p>The back of each tag can be written on or we'll print another message on them for you. Choose one of our standard sizes, or we'll work with your custom size and shape. Please call Customer Service for pricing on custom shapes and sizes.</p> 

     <ul> 
      <li class="ulhead center">Product Specific Info.</li> 
      <li class="ulhead">Stock</li> 
      <li>Printed on durable .020&rdquo; thick plastic</li> 
      <li class="ulhead">Color</li> 
      <li>Neon and metallic colors are not available on Identifcation Tags</li> 

      <li class="ulhead">Production Time</li> 
      <li>Standard production time is approximately 10 days</li> 
      <li class="ulhead">General</li> 
      <li>Tags with no imprint are available, write or call for pricing</li> 
      <li><a href="../../contact_us.php">Contact us</a> for a quote on custom sizes or shapes</li> 

     </ul> 
    </div> 
    <br class="cl cr" /> 
    <table id="pb"> 
     <tr> 
      <td>&nbsp;</td> 
      <td> 
       <table> 
        <tr class="bold"> 

         <td>&nbsp;</td> <td>125</td> <td>250</td> <td>500</td> <td>1,000</td> <td>1,500</td> 
        </tr> 
       </table> 
      </td> 

     </tr> 
     <tr class="mt1"> 
      <td>4-Color Process</td> 
      <td> 
       <table> 
        <tr> 
         <td>Each</td> <td>2.24</td> <td>1.37</td> <td>.86</td> <td>.569</td> <td>.452</td> 
        </tr> 

       </table> 
      </td> 
     </tr> 
     <tr> 
      <td>Black Imprint</td> 
      <td> 
       <table> 
        <tr > 

         <td>Each</td> <td>.48</td> <td>.30</td> <td>.23</td> <td>.156</td> <td>.124</td> 
        </tr> 
       </table> 
      </td> 

     </tr> 
     <tr> 
      <td>&nbsp;</td> 
      <td>5A &nbsp;</td> 
     </tr> 
    </table> 
    <br class="cl cr" /> 
    <h3>ASI 85950 &bull; PPAI 265052 &bull; SAGE 56520<br />All content &copy; 2012 - Blue Frog Printing</h3> 

</div> 
</div> 

而對於包裝的CSS:

#xwraper { 
position:absolute; 
left:50%; 
top:0px; 
width:1px; 
height:100%; 
overflow:visible; 
z-index:-3; 
} 

#wraper { 
position:absolute; 
left:-450px; 
top:0px; 
width:900px; 
height:100%; 
padding-top:110px; 
background-color:#FFFFFF; 
border-left: solid 5px #003860; 
border-right: solid 5px #003860; 
z-index:inherit; 
} 

您還可以,如果想看看www.bluefrogprinting.net/2012/id_tags/看看我在說什麼

+0

完成編輯我的答案:P讓我知道它是否適合你:) – lpd 2012-01-27 16:12:09

回答

2

當您將height屬性設置爲100%時,它假定它的父元素的高度,即元素ID「xwraper」也假定其父元素的高度,默認情況下爲正視圖大小。 (請注意,當您打開和關閉Chrome開發工具時,高度是如何調整的!)顯然,如您所描述的,auto的值只是假定包裝內容所需的最小高度。

額外滾動高度的原因是此元素ID「包裝」中最後一個h3標籤的底部邊距。您需要調整下面的CSS規則,從這些問題而產生:

h3 { 
    font-family:Arial, Helvetica, sans-serif; 
    font-size:15px; 
    width:900px; 
    margin:40px 0px 60px 0px; /* INSERT ALARM BELLS */ 
    text-align:center; 
    float:left; 
} 

要解決的問題,你也應該改變xwraper和wraper你的身高屬性的100%min-height。這兩件事結合起來應該可以達到你想要的樣子。總之,你應該結束於:

#wraper { 
    position: absolute; 
    left: -450px; 
    top: 0px; 
    width: 900px; 
    min-height: 100%; 
    padding-top: 110px; 
    background-color: white; 
    border-left: solid 5px #003860; 
    border-right: solid 5px #003860; 
    z-index: inherit; 
} 

#xwraper { 
    position: absolute; 
    left: 50%; 
    top: 0px; 
    width: 1px; 
    min-height: 100%; 
    overflow: visible; 
    z-index: -3; 
} 

#xwraper #wraper > h3 { 
    margin-bottom: 8px; 
} 
+0

這照顧了包裝的背景不夠長,但它仍然滾動時,它應該都適合在沒有滾動的窗口中。它由於頂部填充而指向滾動,但我如何才能在需要時滾動?感謝您一直以來的幫助。我不知道最小高度是一件事。 – Scotosaurus 2012-01-27 19:26:56

+0

這可能是因爲我在底部保留了一點餘量,請嘗試將最後一條規則更改爲'#xwraper #wraper> h3 {margin-bottom:0;如果你願意的話。請記住,多餘的8像素會推動窗口滾動,而不是每一個分辨率都會以這種方式出現;例如我的1366x768筆記本電腦屏幕只顯示了一個普通的2/3高度滾動條,在版權聲明下有半行空格。 – lpd 2012-01-27 23:14:18

0

嘗試在內容的末尾加上這個

<div style="clear:both"></div> 
0

如果你的包裝沒有對齊到窗口的頂部 - 即它有一個頂部邊距或頂部填充 - 它仍然會調整到窗口高度的100%,但會推過底部這一頁。

但無論哪種方式,張貼更多的代碼將有助於給我們一些上下文!

+0

剛剛添加的代碼... – Scotosaurus 2012-01-27 16:01:02

0

我建議設置一個最小高度。我嘗試在#xwrapper上使用900px,它似乎工作得很好。