Question: I am trying to style a `li` elements to dynamically fit its text content with equal spacing between the `li's` but cannot seem to accomplish this. 

The result currently looks like:
![enter image description here](https://i.stack.imgur.com/Zi2bM.jpg)

I want the white spaces between the `li's` to be consistent but the overall `li's` to be dynamic widths but not exceeding a certain width: (Because there are two different `ul's` they are styles with different paddings so that is why the space sizes are different between the left menu and right menu, but each `li` is consistently spaced in the respective `ul's`) 
![enter image description here](https://i.stack.imgur.com/zFdkV.jpg)

The css is (arbitrarily):

```
li{
   display: inline-block;
   max-width: 95px;
   padding: 5px 10px;
   etc....
}

```

I'm trying to accomplish this using css, avoiding JavaScript or html markup if possible. Thank you.

Answer: 
If you need to have an ordering according the insertion order you need to use an extra element for timestamp.
I.e. on insertions and equal weight use `timestamp` to see which element was inserted first.
So `CustomObject` should be something like: 

```
class CustomObject {  
   int weight;  
   long timestamp;  
}

```

And the comparison should be: 

```
public int compareTo (CustomObject o) {  
    int thisWeight = this.weight;  
    int thatWeight = o.weight;  
    if (thisWeight != thatWeight) {  
        return thisWeight - thatWeight;  
    }  
    else {  
        return this.timestamp - o.timestamp;  
    }  
}  

```

The smaller `timestamp` means it was inserted *earlier* so you keep in the insertion order.

You could also use a "logical" time by maintaining a counter that you update on each `add` or `remove`.
You could use an automatically-incremented sequence number as a secondary key, and use it to break ties.

Javadoc for [`PriorityBlockingQueue`](http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/PriorityBlockingQueue.html) includes an example of this technique:

> 
> Operations on this class make no guarantees about the ordering of elements with equal priority. If you need to enforce an ordering, you can define custom classes or comparators that use a secondary key to break ties in primary priority values. For example, here is a class that applies first-in-first-out tie-breaking to comparable elements. To use it, you would insert a new `FIFOEntry(anEntry)` instead of a plain entry object.
> 
> 
> 
> ```
> class FIFOEntry<E extends Comparable<? super E>>
>      implements Comparable<FIFOEntry<E>> {
>    final static AtomicLong seq = new AtomicLong();
>    final long seqNum;
>    final E entry;
>    public FIFOEntry(E entry) {
>      seqNum = seq.getAndIncrement();
>      this.entry = entry;
>    }
>    public E getEntry() { return entry; }
>    public int compareTo(FIFOEntry<E> other) {
>      int res = entry.compareTo(other.entry);
>      if (res == 0 && other.entry != this.entry)
>        res = (seqNum < other.seqNum ? -1 : 1);
>      return res;
>    }
>  }
> 
> ```
> 
>