css – 具有100%高度和滚动条的IE6“框架”布局

前端之家收集整理的这篇文章主要介绍了css – 具有100%高度和滚动条的IE6“框架”布局前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想实现一个简单的“框架”布局,固定标题,固定左导航区域,以及主要内容区域,如果需要,可以使用滚动条填充视口剩余部分的100%.我最好的尝试是在下面 – 但是当我向主div添加足够的内容以强制滚动时,我看到滚动条延伸到视口底部的下方.

我究竟做错了什么?或者IE6做错了什么,我该如何解决

NB请不要建议使用更新的浏览器 – 我喜欢但不能.

更新1(对于Matti和其他纯粹主义者!) – 我必须生活在为一个团队总部开发Web应用程序的现实限制中,这些应用程序需要由100多个子公司的用户访问,而不是所有子公司都已升级到现代浏览器.有些子公司会喜欢以浏览器不兼容为借口不使用总公司强加的申请!

更新2

我是一名应用程序开发人员,而不是网页设计师,这可能是显而易见的.到目前为止,我一直在使用DOCTYPE HTML 4.0 Transitional,我相信在所有IE版本中强制怪癖模式.但是我最近尝试添加AjaxControlToolkit ModalPopupExtender,这会在显示弹出窗口时弄乱我的布局. Google建议我需要使用XHTML 1.0来解决这个问题(AjaxControlToolkit不支持怪癖模式),事实上我很乐意转向更干净的基于CSS的布局,但我确实需要我的基本框架布局才能在IE6中工作.

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" >
  3. <head>
  4. <title></title>
  5. <style type="text/css">
  6. html,body
  7. {
  8. height:100%;
  9. margin:0;
  10. padding:0;
  11. overflow:hidden;
  12. }
  13. div
  14. {
  15. border:0;
  16. margin:0;
  17. padding:0;
  18. }
  19. div#top
  20. {
  21. background-color:#dddddd;
  22. height:100px;
  23. }
  24. div#left
  25. {
  26. background-color:#dddddd;
  27. float:left;
  28. width:120px;
  29. height:100%;
  30. overflow:hidden;
  31. }
  32. div#main
  33. {
  34. height:100%;
  35. overflow:auto;
  36. }
  37. </style>
  38. </head>
  39. <body>
  40. <div id="top">Title</div>
  41. <div id="left">LeftNav</div>
  42. <div id="main">
  43. Content
  44. <p>
  45. Lorem ipsum ...
  46. </p>
  47. ... repeated several times to force vertical scroll...
  48. <table><tr>
  49. <td>ColumnContent</td>
  50. ... td repeated several times to force horizontal scroll...
  51. <td>ColumnContent</td>
  52. </tr></table>
  53. </div>
  54. </body>
  55. </html>

解决方法

在我之前的回答中,我完全错了(没有双关语),因为你不能在IE6中指定顶部和底部,左右都不能.此外,您不知道内容div的确切宽度和高度,也不知道它们是视口的百分比.

当我解决这个问题时,我将IE置于怪癖模式,以获得border-box box model(另请参阅W3C spec).要为更符合标准的浏览器使用相同的CSS规则,可以使用Box-sizing属性(和变体).执行此操作后,边框进入内容,您可以通过指定边框(宽度和样式)向下和向右推送内容

  1. <!-- put IE in quirks mode -->
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6. <title>IE6 'frames'</title>
  7. <style type="text/css">
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. Box-sizing: border-Box;
  12. -moz-Box-sizing: border-Box;
  13. -khtml-Box-sizing: border-Box;
  14. -webkit-Box-sizing: border-Box;
  15. }
  16.  
  17. html,body {
  18. height: 100%;
  19. overflow: hidden;
  20. }
  21.  
  22. #top {
  23. position: absolute;
  24. top: 0;
  25. width: 100%;
  26. background-color: #ddd;
  27. height: 100px;
  28. z-index: 2;
  29. }
  30.  
  31. #left {
  32. position: absolute;
  33. left: 0;
  34. border-top: 100px solid; /* move everything below #top */
  35. background-color: #bbb;
  36. width: 120px;
  37. height: 100%;
  38. overflow: hidden;
  39. z-index: 1;
  40. }
  41.  
  42. #main {
  43. position: absolute;
  44. border-top: 100px solid;
  45. border-left: 120px solid;
  46. width: 100%;
  47. height: 100%;
  48. overflow: auto;
  49. }
  50. </style>
  51. </head>
  52. <body>
  53. <div id="top">Title</div>
  54. <div id="left">LeftNav</div>
  55. <div id="main">
  56. <p>
  57. Lorem ipsum ...<br />
  58. <!-- just copy above line many times -->
  59. </p>
  60. </div>
  61. </body>
  62. </html>

更新:在IE> = 7和更多符合标准的浏览器中,您可以使用position:fixed以及top和bottom(et al.)规则.有一种方法可以使用CSS expressions在标准模式(或更确切地说,Almost Standards Mode)中在IE6中获得类似框架的外观.这样,您可以让JScript引擎计算宽度和高度的正确值(在条件注释之间添加).

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <title>'Frames' using &lt;div&gt;s</title>
  6. <style type="text/css">
  7. * {
  8. margin: 0;
  9. padding: 0;
  10. }
  11.  
  12. html,body {
  13. height: 100%;
  14. overflow: hidden;
  15. }
  16.  
  17. #top,#left,#main {
  18. position: fixed;
  19. overflow: hidden;
  20. }
  21.  
  22. #top {
  23. top: 0;
  24. width: 100%;
  25. background-color: #ddd;
  26. height: 100px;
  27. }
  28.  
  29. #left {
  30. left: 0;
  31. top: 100px; /* move everything below #top */
  32. bottom: 0;
  33. background-color: #bbb;
  34. width: 120px;
  35. }
  36.  
  37. #main {
  38. top: 100px;
  39. left: 120px;
  40. bottom: 0;
  41. right: 0;
  42. overflow: auto;
  43. }
  44. </style>
  45. <!--[if IE 6]>
  46. <style>
  47. #top,#main {
  48. position: absolute;
  49. }
  50.  
  51. #left {
  52. height: expression((m=document.documentElement.clientHeight-100)+'px');
  53. }
  54.  
  55. #main {
  56. height: expression((m=document.documentElement.clientHeight-100)+'px');
  57. width: expression((m=document.documentElement.clientWidth-120)+'px');
  58. }
  59. </style>
  60. <![endif]-->
  61. </head>
  62. <body>
  63. <div id="top">Title<br /></div>
  64. <div id="left">LeftNav<br /></div>
  65. <div id="main">
  66. <p>
  67. Lorem ipsum ...<br />
  68. <!-- just copy above line many times -->
  69. </p>
  70. </div>
  71. </body>
  72. </html>

也就是说,我不推荐这种方法.它将显着减慢已经不太快的IE6的浏览体验,如these expressions are evaluated many times.

再补充一点:我想你最终会使用外部样式表(和脚本),但是如果你想将它们嵌入到XHTML文档中,请使用“CDATA标记和适用于所用脚本或样式语言的注释”,作为David Dorward recommends.

猜你在找的CSS相关文章