2012-03-28 133 views
0

我正在嘗試設計一個頁面的風格,它非常接近,但我有點困惑。我的pageWrapper div被設置爲佔用100px的固定頂部49px的空間,目前是39px的固定底部。即使這樣渲染效果非常接近預期的效果,但令人困惑的部分是我的頁腳div只設置爲24px的高度。我想知道額外15像素來自哪裏。我懷疑它是我的researchTitle div類的產品,但這是一個包含div的子元素,不應以這種方式影響父元素。下面是我的格式化佈局,而researchTitle設置爲15px的高度使超過100%,造成術語類,它是100%去大CSS佈局問題

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Question.aspx.cs" Inherits="Question" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <style type="text/css"> 
     #header 
     { 
      position: absolute; 
      left: 0; 
      top: 0; 
      width: 100%; 
      height: 49px; 
      background: red; 
      overflow: hidden; 
     } 
     #pageWrapper 
     { 
      position: absolute; 
      height: auto; 
      top: 49px; 
      bottom: 39px; 
      left: 0px; 
      width: 100%; 
     } 
     #questionTop 
     { 
      overflow: auto; 
      position: relative; 
      left: 0; 
      width: 100%; 
      height: 40%; 
      background: blue; 
      overflow: auto; 
     } 
     #questionBottom 
     { 
      position: relative; 
      left: 0; 
      width: 100%; 
      height: 35%; 
      background: green; 
      overflow: auto; 
     } 
     #questionResearch 
     { 
      position: absolute; 
      left: 0; 
      width: 100%; 
      height: 25%; 
     } 

     #terms, #refs, #auth 
     { 
      position: absolute; 
      height: 100%; 
     } 
     #terms 
     { 
      left: 0; 
      width: 34%; 
     } 
     #refs 
     { 
      left: 34%; 
      width: 33%; 
     } 
     #auth 
     { 
      left: 67%; 
      width: 33%; 
     } 
     .researchTitle 
     { 
      position: relative; 
      top: 0; 
      height: 15px; 
      background: #999; 
      width: 100%; 
     } 

     .researchContent 
     { 
      position: relative; 
      overflow: auto; 
      background: #99C; 
      width: 100%; 
      height: 100%; 
     } 
     #footer 
     { 
      position: absolute; 
      left: 0; 
      width: 100%; 
      height: 24px; 
      bottom: 0; 
      background: red; 
      overflow: hidden; 
     } 
    </style> 
</head> 
<body> 
    <div id="header"> 
     Header 
    </div> 
    <div id="pageWrapper"> 
     <div id="questionTop"> 
      <p> 
       First</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Last</p> 
     </div> 
     <div id="questionBottom"> 
      <p> 
       First</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Last</p> 
     </div> 
     <div id="questionResearch"> 
      <div id="terms"> 
       <div class="researchTitle"> 
        Terms</div> 
       <div class="researchContent"> 
        <p> 
         First</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Last</p> 
       </div> 
      </div> 
      <div id="refs"> 
       <div class="researchTitle"> 
        Refs</div> 
       <div class="researchContent"> 
        <p> 
         First</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Last</p> 
       </div> 
      </div> 
      <div id="auth"> 
       <div class="researchTitle"> 
        Authority</div> 
       <div class="researchContent"> 
        <p> 
         First</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Last</p> 
       </div> 
      </div> 
     </div> 
    </div> 
    <div id="footer"> 
     Footer 
    </div> 
</body> 
</html> 
+0

您可以設置演示嗎? – Starx 2012-03-28 02:42:39

+0

你很好奇爲什麼從底部開始的39px距離頁腳的24px高度是15px? – mikevoermans 2012-03-28 02:43:40

+0

額外的15px在哪裏出現? – Starx 2012-03-28 02:49:03

回答

1

你的類researchContent高度設置爲100%設計規範超出預期。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" `"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <style type="text/css"> 
     #header 
     { 
      position: absolute; 
      left: 0; 
      top: 0; 
      width: 100%; 
      height: 49px; 
      background: red; 
      overflow: hidden; 
     } 
     #pageWrapper 
     { 
      position: absolute; 
      height: auto; 
      top: 49px; 
      bottom: 39px; 
      left: 0px; 
      width: 100%; 
     } 
     #questionTop 
     { 
      overflow: auto; 
      position: relative; 
      left: 0; 
      width: 100%; 
      height: 40%; 
      background: blue; 
      overflow: auto; 
     } 
     #questionBottom 
     { 
      position: relative; 
      left: 0; 
      width: 100%; 
      height: 35%; 
      background: green; 
      overflow: auto; 
     } 
     #questionResearch 
     { 
      position: absolute; 
      left: 0; 
      width: 100%; 
      height: 28%; 
     } 

     #terms, #refs, #auth 
     { 
      position: absolute; 
      height: 100%; 
     } 
     #terms 
     { 
      left: 0; 
      width: 34%; 
     } 
     #refs 
     { 
      left: 34%; 
      width: 33%; 
     } 
     #auth 
     { 
      left: 67%; 
      width: 33%; 
     } 
     .researchTitle 
     { 
      position: relative; 
      top: 0; 
      height: 12%; 
      background: #999; 
      width: 100%; 
     } 

     .researchContent 
     { 
      position: relative; 
      overflow: auto; 
      background: #99C; 
      width: 100%; 
      height: 88%; 
     } 
     #footer 
     { 
      position: absolute; 
      left: 0; 
      width: 100%; 
      height: 24px; 
      bottom: 0; 
      background: red; 
      overflow: hidden; 
     } 
    </style> 
</head> 
<body> 
    <div id="header"> 
     Header 
    </div> 
    <div id="pageWrapper"> 
     <div id="questionTop"> 
      <p> 
       First</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Last</p> 
     </div> 
     <div id="questionBottom"> 
      <p> 
       First</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Item</p> 
      <p> 
       Last</p> 
     </div> 
     <div id="questionResearch"> 
      <div id="terms"> 
       <div class="researchTitle"> 
        Terms</div> 
       <div class="researchContent"> 
        <p> 
         First</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Last</p> 
       </div> 
      </div> 
      <div id="refs"> 
       <div class="researchTitle"> 
        Refs</div> 
       <div class="researchContent"> 
        <p> 
         First</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Last</p> 
       </div> 
      </div> 
      <div id="auth"> 
       <div class="researchTitle"> 
        Authority</div> 
       <div class="researchContent"> 
        <p> 
         First</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Item</p> 
        <p> 
         Last</p> 
       </div> 
      </div> 
     </div> 
    </div> 
    <div id="footer"> 
     Footer 
    </div> 
</body> 
</html> 
+0

那麼我會不得不把這些面板包裹在另一個div標籤中來分割空間? – Siegeon 2012-03-28 02:56:27

+0

試試這個。老實說,在高度佈局中同時使用%和像素並不是一個好主意,因爲它會拋棄東西。我不確定你到底想要達到什麼效果,但你應該能夠看到底部三個div的標題 – chadpeppers 2012-03-28 03:15:14

+0

謝謝,當屏幕縮小時,你的解決方案並不適用。無論哪種方式,謝謝你指出這個問題! – Siegeon 2012-03-28 03:38:21