CSS gap between list items in IE7

孤人 提交于 2019-12-12 19:19:17

问题


I'm unable to remove the gap between the list items in IE7.

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <link type="text/css" rel="stylesheet" href="base.css" />
    </head>
    <body>
        <ul>
            <li>
                <div>row 1.1</div>
                <div>row 1.2</div>
            </li> 
            <li>
                <div>row 2.1</div>
                <div>row 2.2</div>
            </li> 
            <li>
                <div>row 3.1</div>
                <div>row 3.2</div>
            </li> 
        </ul>
    </body>
</html>

CSS:

ul
{
    padding: 0px;
    margin: 0px;    
}

li
{
    list-style-type: none;      
    width: 100%;    
    margin: 0px;
    padding: 0px;   
    border-bottom: 1px solid black;
    border-left: 1px solid black;
    border-right: 1px solid black;          
}

li:first-child
{
    border-top: 1px solid black;
}

li div
{
    float: left;
    width: 49.9%;
}

回答1:


float the li too

li
{
    list-style-type: none;      
    width: 100%;
    float: left;    
    margin: 0px;
    padding: 0px;   
    border-bottom: 1px solid black;
    border-left: 1px solid black;
    border-right: 1px solid black;          
}

this will fix IE7 (it's a known issue in IE7) but it will also get other browsers to contain the child floats at the same time - (which they weren't doing)

added: ### Working Example ###




回答2:


IE is really not the problem here.
What happens is you actually have a text node containing "\n\t\t\t" between each of your list items, and since those aren't unbreakable spaces IE interprets them as one " ", which is what you see.
Most of the time problems with IE are caused by the fact that it follows the specification, and people ... don't.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <link type="text/css" rel="stylesheet" href="base.css" />
    </head>
    <body>
        <ul>
            <li>
                <div>row 1.1</div>
                <div>row 1.2</div>
            </li><li>
                <div>row 2.1</div>
                <div>row 2.2</div>
            </li><li>
                <div>row 3.1</div>
                <div>row 3.2</div>
            </li>
        </ul>
    </body>
</html>



回答3:


Also:

<!--[if lte IE 7]>
li {
...
margin-bottom: -3px;
...
}
<![endif]-->


来源:https://stackoverflow.com/questions/5498354/css-gap-between-list-items-in-ie7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!