帮助白色空间:IE中的nowrap和normal

时间:2011-03-20 17:27:27

标签: internet-explorer whitespace

我无法弄明白......

我有一个名为'#ContentContainer'的div,它的宽度为100%,它需要一个带有白色空间的nowrap,所以它的内部扩展和折叠将冒出窗外并创建一个水平滚动。在扩展和崩溃的div中,我有文本和图像。在IE中,这些内部div具有白色空间:nowrap应用于它们......我已将白色空间设置为正常,但IE无法识别..任何人都可以帮忙吗?

这里的CSS:

#ContentContainer {
    position: relative;
    height: 480px;
    width: 100%;
    margin: 10px 0px 0px 0px;
    border: 1px solid blue;
    white-space: nowrap;
}

.column {
    position: relative;
    white-space: normal;
    width: 220px;
    top: 0px;
    border-left: 1px solid #999;
    border-right: 1px solid #999;
    height: 420px;
    margin: 20px 30px 0px 0px;
    *display: inline;
    vertical-align: top;
}

和我的HTML:

<div id="#ContentContainer">
    <div class="column">
        Text that needs to have a white-space or normal.  It needs to wrap.  Text that needs to have a white-space or normal.  It needs to wrap.  Text that needs to have a white-space or normal.  It needs to wrap.  
    </div>

    <div class="column">
        Text that needs to have a white-space or normal.  It needs to wrap.  Text that needs to have a white-space or normal.  It needs to wrap.  Text that needs to have a white-space or normal.  It needs to wrap.  
    </div>

    <div class="column">
        Text that needs to have a white-space or normal.  It needs to wrap.  Text that needs to have a white-space or normal.  It needs to wrap.  Text that needs to have a white-space or normal.  It needs to wrap.  
    </div>

</div>

任何?

2 个答案:

答案 0 :(得分:3)

IE的所有版本都支持white-space:nowrap属性,所以这应该对你有用。

您的问题不是您的CSS,而是HTML中的错误:您有<div id="#ContentContainer">,但这是不正确的:HTML代码中的ID不应包含哈希符号(#)。 CSS代码中需要引用一个ID,但ID本身不应包含它。

所以你的CSS是正确的:

#ContentContainer {
   ....
}

但您的HTML应如下所示:

<div id="ContentContainer">
    ....
希望有所帮助。

答案 1 :(得分:1)

神秘终于在将近三周后终于解决了:似乎正在解析和级联CSS指令white-space:normal;,但真的正在做任何事情(因此有效地制作了空白:nowrap;不朽)是IE 5.5中的一个错误。进入某种“兼容模式”或“怪癖模式”的IE的后续版本可能会重复这种不当行为。它的外观受到IE的确切版本和DOCTYPE的内容 - 甚至内联网与互联网的影响(这解释了为什么它根本没有显示给很多人,为什么这么多的答案似乎没有很有意义。)

确定摆脱这种不当行为的方法是强制所有版本的IE使用更新的渲染模型(下面的示例使用“每个版本都能够使用的最新渲染模型” ),如果可能,需要从Web服务器发送X-UA-Compatible HTTP标头,或者在每个相关文档内作为后备发送它们。对于Apache服务器,添加到.htaccess的命令类似于

Header set X-UA-Compatible "IE=edge,chrome=1"

对于PHP,它应该只添加几行代码,对于IIS,它应该只是一个配置添加。 (您还可以尝试优化仅使用HTML文件发送此标头和/或仅将其发送到IE浏览器。)

如果您无法更改服务器的行为,则回退是添加&lt; head&gt;每个相关文件之前所有 Javascript或CSS 类似于

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">