I am facing an issue with my horizontal navigation bar that contains a dynamic number of links. In this specific case, there are 3 links displayed below:
https://i.sstatic.net/f5vcn.png
My goal is to keep the first two links in their original position and move the third link all the way to the right. I have managed to achieve this by setting a fixed width for the links using
grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
. Then, I applied grid-column-end: -1;
to the element representing the third link.
However, I do not want all the links to have the same width. I would like the widths to be set to auto
, but this approach does not allow me to create an implicit grid stretching across the entire width. Consequently, I am unable to place the third link at the extreme right of the navigation bar. Is there a simple way to accomplish this using CSS Grid? If not, how can I achieve it with Flexbox without resorting to floats or absolute positioning?
Below is the current CSS code I am using:
ul.nav {
display: grid;
grid-auto-flow: column;
align-items: center;
justify-content: start;
grid-gap: 10px;
margin: 0;
padding: 0;
list-style: none;
}