如何使IE尊重最大和最小宽度

时间:2012-06-26 11:48:40

标签: html css internet-explorer

  

可能重复:
  How to make IE support min-width / max-width CSS properties?

我有一个网站,它在列表中有主导航(左侧浮动)。

li元素需要具有最小和最大宽度。 这个css当然适用于所有优秀的浏览器。 但IE(9)对此没有反应。

    ul.dropdown li {
            line-height: normal;
                    text-align: center;
            max-width: 145px;
            min-width: 88px;
            min-height: 30px;
        }

如果我在一个条件下使用此代码,例如max width IE会尊重它。 http://perishablepress.com/maximum-and-minimum-height-and-width-in-internet-explorer/

但当然我不能在min-width中使用相同的。

我需要一个IE尊重最大和最小宽度的解决方案。

有解决方案吗?

谢谢!


编辑:我忘了提及我已经添加了

<!DOCTYPE html&GT;

2 个答案:

答案 0 :(得分:2)

好的,我发现了问题。 它不在代码中,我的IE只是自动切换到Quirks模式。 通过进入控制台(F12)并将文档模式更改为IE9来更改它!

谢谢!

答案 1 :(得分:0)

试试这个(它在我的ie8上工作)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>template</title>
<style type="text/css">
 #content{
   height:400px;
   background:yellow;
   *width: expression(if(document.body.clientWidth < 534){"533px";}else if(document.body.clientWidth > 776){"777px";}else{ "auto"; }); /* set min-width for IE */
   background: red;
 }

</style>


</head>
<body>
<div id="content">
hello
</div>
</body>
</html>

我不知道怎么写这个?并且:。

哈克宽度:http://paulirish.com/2009/browser-specific-css-hacks/