2012-03-28 134 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