Imagine if I have a collection of N words. To illustrate, consider the following:
- Dog
- Peanut
- Oranges
- Lemon
- Disciplinary
All these words vary in length.
Let's assume there is a container with a variable width X (the container may adjust its size according to the page).
My goal is to arrange the words on a horizontal line with N-1 equal spaces between them. There should be no space to the left of the leftmost word or to the right of the rightmost word. The left side of the leftmost word should align with the left side of the container, and the right side of the rightmost word should align with the right side of the container.
Here is an image depicting how I envision it: https://i.sstatic.net/rvPxi.png
What would be the most effective way to achieve this using HTML/CSS/JS?
My initial thoughts were:
- Using the calc() function, but how do I determine the text width?
- Setting margins to 0 auto, but will this work with multiple elements? What about browser compatibility?
- Utilizing CSS flexbox, although I have limited experience with it.
- Implementing some clever JavaScript solution, but how?
Note: I came across this thread, which is similar but not precisely what I'm seeking: Equal and full width navigation