【问题标题】:How to align text correctly?如何正确对齐文本?
【发布时间】:2013-03-03 05:46:33
【问题描述】:

我正在尝试在 html 中制作链接列表。默认情况下,链接都对齐到容器的左侧 但是当字体改变时(即字体大小:1.5em;),线条形成金字塔图案并且不包含最后一个数字。

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;
}

【问题讨论】:

  • 你没有清除你的浮动。

标签: html css alignment font-size


【解决方案1】:
.links {
    overflow:hidden;
}

Clear:both;

【讨论】:

  • 你知道为什么会溢出:隐藏;使内容 div 包含 10?
【解决方案2】:

只需从您的等级类别中删除浮动

.rank 
{
/*float:left*/
}

【讨论】:

    猜你喜欢
    • 2011-09-08
    • 2016-09-21
    • 2013-02-11
    • 2013-03-18
    • 2018-07-31
    • 2013-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多