html - justify-content property is not working as expected -
i'm trying align "previous" left, align "next" right, , figure out how center page numbers.
i've been looking @ tutorials , articles on flexbox i'm having hard time understanding it.
.nav-links { display: flex; } .prev.page-numbers { justify-content: flex-start; } .next.page-numbers { justify-content: flex-end; }
<div class="nav-links"> <a class="prev page-numbers">previous</a> <a class="page-numbers">1</a> <a class="page-numbers">2</a> <a class="page-numbers">3</a> <a class="next page-numbers">next</a> </div>
the justify-content
property applies flex containers, although aligns flex items.
in code, because you're applying justify-content
flex items, being ignored.
here 2 working examples:
example 1 - justify-content
.nav-links { display: flex; justify-content: space-between; background-color: lightgray; } { flex: 0 0 10%; text-align: center; border: 1px solid black; background-color: yellow; }
<div class="nav-links"> <a class="prev page-numbers">previous</a> <a class=" page-numbers">1</a> <a class="page-numbers">2</a> <a class=" page-numbers">3</a> <a class="next page-numbers">next</a> </div>
example 2 - auto
margins
.nav-links { display: flex; background-color: lightgray; } { flex: 0 0 10%; text-align: center; border: 1px solid black; background-color: yellow; } a:first-child { margin-right: auto; } a:last-child { margin-left: auto; }
<div class="nav-links"> <a class="prev page-numbers">previous</a> <a class=" page-numbers">1</a> <a class="page-numbers">2</a> <a class=" page-numbers">3</a> <a class="next page-numbers">next</a> </div>
more details: