我究竟做错了什么?或者IE6做错了什么,我该如何解决?
NB请不要建议使用更新的浏览器 – 我喜欢但不能.
更新1(对于Matti和其他纯粹主义者!) – 我必须生活在为一个团队总部开发Web应用程序的现实限制中,这些应用程序需要由100多个子公司的用户访问,而不是所有子公司都已升级到现代浏览器.有些子公司会喜欢以浏览器不兼容为借口不使用总公司强加的申请!
更新2
我是一名应用程序开发人员,而不是网页设计师,这可能是显而易见的.到目前为止,我一直在使用DOCTYPE HTML 4.0 Transitional,我相信在所有IE版本中强制怪癖模式.但是我最近尝试添加AjaxControlToolkit ModalPopupExtender,这会在显示弹出窗口时弄乱我的布局. Google建议我需要使用XHTML 1.0来解决这个问题(AjaxControlToolkit不支持怪癖模式),事实上我很乐意转向更干净的基于CSS的布局,但我确实需要我的基本框架布局才能在IE6中工作.
- <!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>
- <title></title>
- <style type="text/css">
- html,body
- {
- height:100%;
- margin:0;
- padding:0;
- overflow:hidden;
- }
- div
- {
- border:0;
- margin:0;
- padding:0;
- }
- div#top
- {
- background-color:#dddddd;
- height:100px;
- }
- div#left
- {
- background-color:#dddddd;
- float:left;
- width:120px;
- height:100%;
- overflow:hidden;
- }
- div#main
- {
- height:100%;
- overflow:auto;
- }
- </style>
- </head>
- <body>
- <div id="top">Title</div>
- <div id="left">LeftNav</div>
- <div id="main">
- Content
- <p>
- Lorem ipsum ...
- </p>
- ... repeated several times to force vertical scroll...
- <table><tr>
- <td>ColumnContent</td>
- ... td repeated several times to force horizontal scroll...
- <td>ColumnContent</td>
- </tr></table>
- </div>
- </body>
- </html>
解决方法
当我解决这个问题时,我将IE置于怪癖模式,以获得border-box box model(另请参阅W3C spec).要为更符合标准的浏览器使用相同的CSS规则,可以使用Box-sizing属性(和变体).执行此操作后,边框进入内容,您可以通过指定边框(宽度和样式)向下和向右推送内容:
- <!-- put IE in quirks mode -->
- <!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>
- <title>IE6 'frames'</title>
- <style type="text/css">
- * {
- margin: 0;
- padding: 0;
- Box-sizing: border-Box;
- -moz-Box-sizing: border-Box;
- -khtml-Box-sizing: border-Box;
- -webkit-Box-sizing: border-Box;
- }
- html,body {
- height: 100%;
- overflow: hidden;
- }
- #top {
- position: absolute;
- top: 0;
- width: 100%;
- background-color: #ddd;
- height: 100px;
- z-index: 2;
- }
- #left {
- position: absolute;
- left: 0;
- border-top: 100px solid; /* move everything below #top */
- background-color: #bbb;
- width: 120px;
- height: 100%;
- overflow: hidden;
- z-index: 1;
- }
- #main {
- position: absolute;
- border-top: 100px solid;
- border-left: 120px solid;
- width: 100%;
- height: 100%;
- overflow: auto;
- }
- </style>
- </head>
- <body>
- <div id="top">Title</div>
- <div id="left">LeftNav</div>
- <div id="main">
- <p>
- Lorem ipsum ...<br />
- <!-- just copy above line many times -->
- </p>
- </div>
- </body>
- </html>
更新:在IE> = 7和更多符合标准的浏览器中,您可以使用position:fixed以及top和bottom(et al.)规则.有一种方法可以使用CSS expressions在标准模式(或更确切地说,Almost Standards Mode)中在IE6中获得类似框架的外观.这样,您可以让JScript引擎计算宽度和高度的正确值(在条件注释之间添加).
- <!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>
- <title>'Frames' using <div>s</title>
- <style type="text/css">
- * {
- margin: 0;
- padding: 0;
- }
- html,body {
- height: 100%;
- overflow: hidden;
- }
- #top,#left,#main {
- position: fixed;
- overflow: hidden;
- }
- #top {
- top: 0;
- width: 100%;
- background-color: #ddd;
- height: 100px;
- }
- #left {
- left: 0;
- top: 100px; /* move everything below #top */
- bottom: 0;
- background-color: #bbb;
- width: 120px;
- }
- #main {
- top: 100px;
- left: 120px;
- bottom: 0;
- right: 0;
- overflow: auto;
- }
- </style>
- <!--[if IE 6]>
- <style>
- #top,#main {
- position: absolute;
- }
- #left {
- height: expression((m=document.documentElement.clientHeight-100)+'px');
- }
- #main {
- height: expression((m=document.documentElement.clientHeight-100)+'px');
- width: expression((m=document.documentElement.clientWidth-120)+'px');
- }
- </style>
- <![endif]-->
- </head>
- <body>
- <div id="top">Title<br /></div>
- <div id="left">LeftNav<br /></div>
- <div id="main">
- <p>
- Lorem ipsum ...<br />
- <!-- just copy above line many times -->
- </p>
- </div>
- </body>
- </html>
也就是说,我不推荐这种方法.它将显着减慢已经不太快的IE6的浏览体验,如these expressions are evaluated many times.
再补充一点:我想你最终会使用外部样式表(和脚本),但是如果你想将它们嵌入到XHTML文档中,请使用“CDATA标记和适用于所用脚本或样式语言的注释”,作为David Dorward recommends.