0

I'm making a navigation menu and have run into the common problem of needing to horizontally align a UL with equal spacing around each list item. However, this list is inside of a div set to a width of 1100px and I need there to be no space on the left or right-hand sides of the div -- the first and last list items need to reach their side of the div.

Here's the unordered list as I have it right now:

ul{
            width:100%;
            display:table;
            list-style-type:none;
            padding:0;
            border-spacing:5px;
            li{
                display:table-cell;
                padding:0 30px;
            }
        }

And as I said, this unordered list is inside of another div which has its width set to 1100px. What should I do to make the list stretch the full width of the div?

Tom Maxwell
  • 9,273
  • 17
  • 55
  • 68

2 Answers2

1

1) Set text-align:justify on the container

2) Use a pseudo element to stretch the list items to 100% of the width of the list

FIDDLE

ul {
  width: 800px;
  text-align: justify;
  list-style-type: none;
  padding: 0;
  background: yellow;
}
ul:after {
  content: '';
  display: inline-block;
  width: 100%;
}
li {
  display: inline-block;
  padding: 0 30px;
  text-align: center;
  background: tomato;
}
<div id="explore-nav">
  <ul>
    <li>Example</li>
    <li>Example</li>
    <li>Example</li>
    <li>Example</li>
  </ul>
</div>
Danield
  • 121,619
  • 37
  • 226
  • 255
0

Guessing your markup look something like this.

ul {
  width: 100%;
  display: table;
  list-style-type: none;
  padding: 0;
  border-spacing: 5px;
  border: 1px solid black;
}
li {
  display: table-cell;
  padding: 0 30px;
  text-align: center;
  background-color: #EDEDED;
  border: 1px solid black;
}
#container {
  width: 1100px;
  margin: 0 auto;
}
<div id="container">
  <ul>
    <li>Test</li>
    <li>Test</li>
    <li>Test</li>
    <li>Test</li>
    <li>Test</li>
  </ul>
</div>
Weafs.py
  • 22,731
  • 9
  • 56
  • 78