The Code A is from the article.
The Image A is the result of Code A.
I hope to desgin a UI just like Image B, the two labels on the left of the bar, and the two labels on the right of the bar.
But Code B can’t get the result, how can I do?
Code A
<nav>
<ul>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3 is longer</a></li>
<li class="push-right"><a href="#">Page 4</a></li>
</ul>
</nav>
nav ul {
display: flex;
margin: 0 -10px;
}
nav li {
margin: 0 10px;
}
.push-right {
margin-left: auto;
}
Code B
<nav>
<ul>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li class="push-right"><a href="#">Page 3 is longer</a></li>
<li class="push-right"><a href="#">Page 4</a></li>
</ul>
</nav>
//The same
Image A
Image B
Added Content
Thanks! Maybe the Code C is good way.
Code C
<nav>
<ul>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li class="push-right"><a href="#">Page 3 is longer</a></li>
<li ><a href="#">Page 4</a></li>
</ul>
</nav>
nav ul {
display: flex;
margin: 0 -10px;
}
nav li {
margin: 0 10px;
}
.push-right {
margin-left: auto;
}
2
Answers
Put the "push-right" class on the third item, not the fourth. It then pushes both to the right.