【发布时间】:2012-04-17 07:28:32
【问题描述】:
我是 CSS 新手,之前从未创建过布局,我在 Internet Explorer 中的第一个布局遇到了一些问题。我认为它在 Firefox 中看起来不错。 在开始布局之前,我已经阅读了大量有关 HTML 和 CSS 的内容,所以我知道 IE 有一些错误,但即使在制作布局和研究问题之后,这些解决方案似乎都没有奏效。我希望这里有人可以提供帮助。
TL;DR:新布局在 IE 中不起作用,需要帮助(进行了研究)
问题 1:与 Firefox 相比,IE 中的 2 个右侧边栏太宽。其他一切看起来都很正常,只是那两个太宽了,影响了布局 问题 2:当窗口宽度低于 1024 时,它应该从 container1.css 切换到 container2.css,从而有效地更改容器属性以更好地以较小的分辨率显示。在 Firefox 中效果很好,但在 IE 中,它似乎删除了容器期间,使内容在整个窗口中流动。
<HTML>
<HEAD>
<TITLE>My Liquid Layout</TITLE>
<link rel="stylesheet" type="text/css" href="LiquidLayout.css" />
<link id="container1" rel="stylesheet" type="text/css" href="container1.css" />
<link id="container2" rel="alternate" type="text/css" href="container2.css" />
<script type="text/javascript">
<!--
var css = "container1";
function changeStyle(styleSheet)
{
if(styleSheet == css)
return;
var selected = document.getElementById(styleSheet);
var current = document.getElementById(css);
if(!selected)
{
selected = current.cloneNode(true);
selected.id=styleSheet;
selected.setAttribute("href",current.getAttribute("href").replace(new
RegExp(css),styleSheet));
}
current.setAttribute("rel","stylesheet1");
selected.setAttribute("rel","stylesheet");
document.getElementsByTagName('head')[0].appendChild(selected);
css = styleSheet;
}
function windowSize()
{
var windowWidth;
var windowHeight;
windowWidth = window.innerWidth;
windowHeight = window.innerHeight;
if (document.body && document.body.offsetWidth)
{
windowWidth = document.body.offsetWidth;
windowHeight = document.body.offsetHeight;
}
if (document.compatMode=='CSS1Compat' &&
document.documentElement &&
document.documentElement.offsetWidth )
{
windowWidth = document.documentElement.offsetWidth;
windowHeight = document.documentElement.offsetHeight;
}
if (window.innerWidth && window.innerHeight)
{
windowWidth = window.innerWidth;
windowHeight= window.innerHeight;
}
if(windowWidth < 1024)
changeStyle('container2');
else if(windowWidth >= 1024)
changeStyle('container1');
}
window.onresize = new Function("windowSize()");
//-->
</script>
</HEAD>
<BODY>
<div id = "container">
<div id = "header"><p id = "size"></p></div>
<div id = "content">
<div id = "menu">
<ul>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Home</a></li>
<li><a href="#">Video</a></li>
<li><a href="#">Gallery</a></li>
<li><a href="#">IGN</a></li>
</ul>
</div>
<div id = "sidebox"></div>
<div class = "column" id = "sidebar"></div>
<div class = "column" id = "main"></div>
</div>
<div id = "footer"></div>
</div>
</BODY>
</HTML>
主要的CSS是:
body
{
background-color:gray;
margin: 0px;
text-align: center;
}
#header
{
width: 100%;
height: 200px;
background-color: yellow;
}
#content
{
padding-top:5px;
padding-bottom:0px;
padding-right:5px;
padding-left:5px;
min-height: 768px;
}
#menu
{
width: 66%;
height: 250px;
background-color: blue;
float: left;
}
#sidebox
{
width: 34%;
height: 250px;
background-color: red;
float: right;
display: inline;
}
#sidebar
{
width: 34%;
background-color: red;
height: 100%;
float: right;
}
#main
{
width: 65%;
height: 100%;
background-color: green;
float: left;
}
如果有人能提供一些关于在 IE 中解决这些问题的建议,我将不胜感激! 也欢迎任何改进建议
【问题讨论】:
-
你没有使用文档类型,所以 IE 使用了错误的盒子模型(它在 quirksmode 中运行)。
-
另外,考虑使用 jQuery 而不是 vanilla javascript。 jQuery 帮助修复了很多与 IE 的不兼容以及其他跨浏览器问题
标签: javascript html css liquid-layout