简体   繁体   English

IE和空白

[英]IE and white-space

I have PHP creating an inline unordered list from an array. 我有PHP从数组创建一个内联无序列表。 For each of these list items, I need to specify "white-space: nowrap" because I have checkboxes next to text, and they should not be separated. 对于这些列表项中的每一个,我都需要指定“空白:nowrap”,因为我在文本旁边有复选框,并且不应将其分开。 However, the list should otherwise be wrapping normally, because it shouldn't apply outside the list items. 但是,该列表应该以其他方式正常包装,因为它不应应用于列表项之外。

<ul>
    <?php
    foreach ($nonfiction as $nonficid => $nonficgenre) {
        echo "<li><input type=\"checkbox\" name=\"genre[]\" value=\"$nonficgenre\"";
        if (in_array($nonficgenre, $selectedgenres)) {
            echo " checked=\"checked\"";
        }
        echo " /><span class=\"genrelabel\">$nonficgenre</span></li> ";
    }
    ?>
</ul>

And in my CSS (note: the whole list is in a div of class "listdivs"): 在我的CSS中(请注意:整个列表位于“ listdivs”类的div中):

.listdivs li {
    display: inline;
    white-space: nowrap;
}

This works fine in Chrome and Firefox, which wraps the list around at the appropriate break. 此功能在Chrome和Firefox上运行良好,可以在适当的时间将列表包装起来。 But IE ignores the legitimate white spaces and prints the whole list out on one line. 但是IE会忽略合法的空格,并将整个列表打印在一行上。 How can I compensate for this? 我该如何补偿?

try to add an span arround content. 尝试添加跨度周围的内容。

.listdivs li {
    display: inline;
    white-space: nowrap;
}
.listdivs li span {
    white-space: nowrap;
}

<ul>
    <?php
    foreach ($nonfiction as $nonficid => $nonficgenre) {
        echo "<li><span><input type=\"checkbox\" name=\"genre[]\" value=\"$nonficgenre\"";
        if (in_array($nonficgenre, $selectedgenres)) {
            echo " checked=\"checked\"";
        }
        echo " /><span class=\"genrelabel\">$nonficgenre</span></span></li> ";
    }
    ?>
</ul>

This trick is used alot in some ui, like jqueryui, yahooui, extjs 这个技巧在某些ui中使用很多,例如jqueryui,yahooui,extjs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM