tags:

views:

33

answers:

1

CSS:

.homeBar li {
    float: center;
    display: inline;
    text-align: center;
    font-family: Tahoma;
    font-size: 13px;
    list-style: none;
}
.homeBar img {
    color: #94938e;
    margin-right: 30px;
    text-decoration: none;

}

HTML:

<ul class="homeBar">
    <li><a href="#"><img src="images/friends.png"></a></li>
    <li><a href="#"><img src="images/mail.png"></a></li>
</ul>

as you can see i tried float: center, but it wont center it..

A: 

If the widths of your elements (and thus, your list) are known, you could display the list as inline-block, and apply auto margins to it:

.homeBar li {
    width: /* Full width (calculate it manually) */;
    display: inline-block;
    margin: 0 auto;
}

The width used should be the width of the images, plus padding and margin, after any margin collapse.

You
cant get this to center, i did 157px ( 48 x 2 + 60px padding) and it just goes alittle to the right..
Karem
That might be because *both* your `<li>` elements have a right margin — that means the last one will have 30px of empty space to its right which affect the centering. Apply a border to your `<ul>` and you'll see that it is in fact centered.
You
No its not centered. I even tried removing the margin-right but no results at all
Karem
There's also the fact that 2x48+60≠157 — the correct value would be 156, or 126 if you omit margin on the rightmost `<li>`. It *will* be centered **in the parent element**. Make sure your parent element is as wide as the area in which you want your `<ul>` centered.
You