CSS - 进行绝对定位时字间距不起作用

时间:2013-06-18 15:44:29

标签: html css css3 position word-spacing

我有一个div和一些跨度。我有一个问题,当我使用绝对定位时,我的word-spacing属性无法正常工作。

要获得更多许可,{jsFiddle是here

HTML:

<section id="header">
    <span>HOME</span>
    <span class="no-spacing">ABOUT US</span>
    <span>PORTFOLIO</span>
    <span class="no-spacing">CONTACT US</span>
</section>

CSS:

html, body{
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
}

#header {
    width: 100%;
    height: 30%;
    background-image: url(http://www.7daysinhavana.com/wordpress/wp-content/themes/7days/images/commun/back_header_global.jpg);
    font-family: 'GarageGothicBlackRegular';
    word-spacing: 20px;
    font-size: 25px;
    text-align: center;
    position: relative;
}

#header span {
    position: absolute;
    bottom: 0px;
}

.no-spacing {
    word-spacing: 0px;
}

如何修复该错误?

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

将您的跨度包裹在div(或其他容器)中并将容器放置如下:

<section id="header">
    <div>
        <span>HOME</span>
        <span class="no-spacing">ABOUT US</span>
        <span>PORTFOLIO</span>
        <span class="no-spacing">CONTACT US</span>
    </div>
</section>

CSS

#header div {
    position: absolute;
    width:100%;
    bottom: 0px;
}

<强> jsFiddle example