如何正确对齐文本?

时间:2013-03-02 21:38:29

标签: html css alignment font-size

我正在尝试在html中创建链接列表。默认情况下,链接全部对齐容器normal alignment的左侧 但是当字体改变时(即字体大小:1.5em;),这些线条形成金字塔图案,并且不包含最后一个数字。 links in pyramid pattern

firefox和chrome都会出现此问题。

这是html

    <div id="container">
        <div id="content">
            <div class="links">
                <span class="rank" style="width:2.20ex;" >1</span>
                <a href="http://www.youtube.com/">this is a test</a>
            </div>
            <div class="links">
                <span class="rank" style="width:2.20ex;" >2</span>
                <a href="http://www.youtube.com/">this is a test</a>
            </div>
            <div class="links">
                <span class="rank" style="width:2.20ex;" >3</span>
                <a href="http://www.youtube.com/">this is a test</a>
            </div>
            <div class="links">
                <span class="rank" style="width:2.20ex;" >4</span>
                <a href="http://www.youtube.com/">this is a test</a>
            </div>
            <div class="links">
                <span class="rank" style="width:2.20ex;" >5</span>
                <a href="http://www.youtube.com/">this is a test</a>
            </div>
            <div class="links">
                <span class="rank" style="width:2.20ex;" >6</span>
                <a href="http://www.youtube.com/">this is a test</a>
            </div>
            <div class="links">
                <span class="rank" style="width:2.20ex;" >7</span>
                <a href="http://www.youtube.com/">this is a test</a>
            </div>
            <div class="links">
                <span class="rank" style="width:2.20ex;" >8</span>
                <a href="http://www.youtube.com/">this is a test</a>
            </div>
            <div class="links">
                <span class="rank" style="width:2.20ex;" >9</span>
                <a href="http://www.youtube.com/">this is a test</a>
            </div>
            <div class="links">
                <span class="rank" style="width:2.20ex;" >10</span>
                <a href="http://www.youtube.com/">this is a test</a>
            </div>
        </div>
    </div>

这是css

#container {
    margin: 0 auto;
    width: 1024px;
}

#content {
    background-color: green;
}

.rank {
    color: #c63131;
    float: left;
    font-family; arial;
    font-size: 1.5em;
    margin-right: 0.2em;
    text-align: right;
}

.links {
    margin-left: 3px;
}

.links a {
    text-decoration: none;
}

2 个答案:

答案 0 :(得分:1)

.links {
    overflow:hidden;
}

Clear:both;

答案 1 :(得分:1)

只需从等级类中删除浮动

.rank 
{
/*float:left*/
}