bab
bab

Reputation: 2169

How to align text correctly?

I am trying to make a list of links in html. By default, the links all align towards the left side of the container normal alignment but when the font is changed (i.e. font-size: 1.5em;) the lines form a pyramid pattern and the last number is not contained. links in pyramid pattern

This problem occurs in both firefox and chrome.

Here is 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>

Here is the 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;
}

Upvotes: 1

Views: 105

Answers (2)

Sachin
Sachin

Reputation: 40970

Just remove float from your rank class

.rank 
{
/*float:left*/
}

Upvotes: 1

zloctb
zloctb

Reputation: 11177

.links {
    overflow:hidden;
}

or Clear:both;

Upvotes: 1

Related Questions