浏览器将空格放在代码中没有的位置

时间:2012-04-09 20:01:12

标签: html

为什么以下标记在每个<li></li>之后产生一个空格,当源中没有空格时?如果我将它们全部放在一行上,则在预览页面时空格会消失。但是为什么浏览器将我的标签作为空格读取?

(您可以在第一张图片的左侧看到服务旁边的边框。在边框和服务之间是空格。图片2中没有。)

enter image description here

<nav>
    <ul>
        <li><a href="#" class="active">HOME</a></li>
        <li><a href="#">SERVICES</a></li>
        <li><a href="#">PRODUCTS</a></li>
        <li><a href="#">ABOUT</a></li>
        <li><a href="#">CONTACT</a></li>
        <li><a href="#">LIKE US</a></li>
    </ul>
</nav>

这里删除了所有标签:

enter image description here

<nav>
    <ul>
        <li><a href="#" class="active">HOME</a></li><li><a href="#">SERVICES</a></li><li><a href="#">PRODUCTS</a></li><li><a href="#">ABOUT</a></li><li><a href="#">CONTACT</a></li><li><a href="#">LIKE US</a></li>
    </ul>
</nav>

编辑:

浏览器是OSX Lion上的Safari 5.1.5。编辑是Espresso。还试过TextMate。这是导航的CSS。

nav {
    position: relative;
    width: 960px;
    padding: 0 30px;
    background: #281601; /* Old browsers */
    background: -moz-linear-gradient(left,  #3f2c16 0%, #281601 5%, #281601 95%, #3f2c16 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, right top, color-stop(0%,#3f2c16), color-stop(5%,#281601), color-stop(95%,#281601), color-stop(100%,#3f2c16)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(left,  #3f2c16 0%,#281601 5%,#281601 95%,#3f2c16 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(left,  #3f2c16 0%,#281601 5%,#281601 95%,#3f2c16 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(left,  #3f2c16 0%,#281601 5%,#281601 95%,#3f2c16 100%); /* IE10+ */
    background: linear-gradient(left,  #3f2c16 0%,#281601 5%,#281601 95%,#3f2c16 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#3f2c16', endColorstr='#3f2c16',GradientType=1 ); /* IE6-9 */
    font-family: 'Crimson Text', serif;
    color: #fff;
}

nav:before {
    position: absolute;
    left: -12px;
    top: 0px;
    content: url('../img/nav-left.png');
}

nav:after {
    position: absolute;
    left: 960px;
    top: 0px;
    content: url('../img/nav-right.png');
}

nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

nav ul li {
    display: inline-block;
}

nav ul li a, nav ul li a:visited {
    display: block;
    color: #c7beb4;
    text-decoration: none;
    font-size: 95%;
    letter-spacing: 0.08em;
    padding: 12px 20px;
    border-right: 1px solid #3b2b18;
}

nav ul li:first-child a:before {
    content: url('../img/nav-icon-home.png');
    margin: 0px 8px 0 0;
}

nav ul li:first-child a:hover:before {
    content: url('../img/nav-icon-home-active.png');
}

nav ul li:last-child {
    float: right;
}

nav ul li:last-child a {
    border:none;
}

nav ul li:last-child a:before {
    content: url('../img/nav-icon-facebook.png');
    margin: 0px 8px 0 0;
}

nav ul li:last-child a:hover:before {
    content: url('../img/nav-icon-facebook-active.png');
}

nav ul li a:hover {
    background: #c7beb4;
    color: #281601;
    box-shadow: inset 0 0 15px rgba(40,22,1,0.5);
}

1 个答案:

答案 0 :(得分:0)

更改了li的显示以显示:table-cell而不是display:inline-block。