tags:

views:

664

answers:

9

After some search, I did not find a proper way to center a list of <li> into a fixed width div... any solution there ?

--

take a look at the page.. dont work !

A: 

Try

div#divID ul {margin:0 auto;}
Keir
+2  A: 

Since ul and li elements are display: block by default — give them auto margins and a width that is smaller than their container.

ul {
    width: 70%;
    margin: auto;
}

If you've changed their display property, or done something that overrides normal alignment rules (such as floating them) then this won't work.

David Dorward
as you said, float left was the problem ! thanks
marc-andre menard
A: 

For what type of justification?

KalaATX
+1  A: 

To center a block object (e.g. the ul) you need to set a width on it and then you can set that objects left and right margins to auto.

To center the inline content of block object (e.g. the inline content of li) you can set the css property text-align: center;.

anddoutoi
+1  A: 

Could either be

div ul
{
 width: [INSERT FIXED WIDTH]
 margin: 0 auto;
}

or

div li
{
text-align: center;
}

depends on how it should look like (or combining those)

ApoY2k
The latter option wouldn't center the list items, only their inline content.
David Dorward
Still, if the `<li>` aren't styled, it looks the same.
ApoY2k
A: 

use oldschool center-tags

<div> <center> <ul> <li>...</li> </ul></center> </div>

:-)

justastefan
You should avoid using style-type expressions in markup-code. That's what CSS was made for!
ApoY2k
Workable but do note that: "The `center` element was deprecated in HTML 4.01, and is not supported in XHTML 1.0 Strict DTD" from http://www.w3schools.com/TAGS/tag_center.asp
o.k.w
*sigh* W3Schools providing incomplete, wrong information as usual. It was deprecated in 4.0 not 4.01, and doesn't appear in any Strict variant (singling out XHTML 1.0 is an odd choice).
David Dorward
As mentioned before these were deprecated in HTML 4.01 ... also that's just bad practice ...
Jonny Haynes
A: 

If you know the width of the ul then you can simply set the margin of the ul to 0 auto;

This will align the ul in the middle of the containing div

Example:

HTML:

<div id="container">
 <ul>
  <li>Item1</li>
  <li>Item2</li>
 </ul>
<div>

CSS:

  #container ul{
    width:300px;
    margin:0 auto;
  }
Jamie Dixon
A: 

Just add text-align: center; to your <ul>. Problem solved.

Jonny Haynes
+1  A: 
<div id="container">
  <table width="100%" height="100%">
    <tr>
      <td align="center" valign="middle">
        <ul>
          <li>item 1</li>
          <li>item 2</li>
          <li>item 3</li>
        </ul>
      </td>
    </tr>
  </table>
</div>
Yo Momma