Making an unordered list stretch horizontally so as to always fill up a div
Asked Answered
P

3

7

Sorry about this, I thought this issue was resolved, but then it turned out that it wasn't.

I have an unordered list inside a div, and I want the list to always fill up the entire div horizontally, no matter what the zoom level. How does one go about this? Set the width of each list item individually? I tried this, and the widths of my items do add up to 100%, yet the list still does not fill up the div. I'm modifying a template, too, so much of the HTML is hidden from me, but I can edit CSS all I want to. What else can I do in terms of CSS? Padding? Something involving the calc function? I've experimented with all of these, but somehow nothing seems to work.

Are there any other ideas as to how this can be done?

Postconsonantal answered 12/9, 2013 at 5:30 Comment(0)
A
17

Try this

 ul { padding:0; margin:0; white-space:nowrap; }
 li { width: 100%; list-style-type:none; display:inline-block; }

or

ul {
  width: 100%;
  display: table;
  table-layout: fixed;
}

ul li {
  display: table-cell;
  width: auto;
  text-align: center;
}
Aloke answered 12/9, 2013 at 5:35 Comment(0)
B
3

The browser support is a bit iffy, but if you want your list items to always take up the full width of their container, you can use a combination of display: table and display: table-cell with your list items:

ul {
    display: table;
}

li {
    display: table-cell;
}
Butch answered 12/9, 2013 at 5:39 Comment(0)
N
1

You can try this Html:

<ul>
    <li>first list</li>
    <li>Second</li>
    <li>Third list</li>
    <li>Fourth</li>
</ul>

CSS:

body {
    border: 1px dashed #CCC;   
    margin: 5px;
    min-height:400px;
}
ul, li {
    list-style: none;
    margin: 0;
    padding: 0;
}
ul {
    width: 100%;
}
li {
    float: left;
    width: 25%;  
    text-align:center;
}

Check this fiddle : http://jsfiddle.net/Kritika/tfSSe/

Neo answered 12/9, 2013 at 6:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.