Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal List That Evenly Divides Remaining Space via CSS

I have a web app that uses Bootstrap. In this web app, I have a dynamically created list of items. An example of the items that are created is presented here:

<ul class="list-inline">
  <li>home</li>
  <li>contact me</li>
  <li>a longer list item</li>
</ul>

When this gets rendered, its something like this:

+------------------------------------------------+
| +------+------------+--------------------+     |
| | home | contact me | a longer list item |     |
| +------+------------+--------------------+     |
+------------------------------------------------+

However, I'd like to figure out a way to make the items fill the width of the screen and be evenly distributed. In other words, I kind of want it like this:

+-----------------------------------------------------------------------------------+
| +--------------------------+--------------------------+--------------------------+     |
| |           home           |        contact me        |    a longer list item    |     |
| +--------------------------+--------------------------+--------------------------+     |
+-----------------------------------------------------------------------------------+

In the example above, each item is the same width and the text is centered within each cell. How do I do this in Bootstrap?

Thank you!

like image 682
JQuery Mobile Avatar asked Aug 21 '15 12:08

JQuery Mobile


1 Answers

You can use display: flex

.list-inline {
  display: flex;
}

.list-inline li {
  flex: 1;

  text-align: center;
}
like image 139
Dan Gamble Avatar answered Sep 19 '22 01:09

Dan Gamble