Source

Oju-iwe

Iwe ati awọn apẹẹrẹ fun fifi oju-iwe han lati tọka lẹsẹsẹ ti akoonu ti o ni ibatan wa kọja awọn oju-iwe pupọ.

Akopọ

A lo bulọọki nla ti awọn ọna asopọ asopọ fun pagination wa, ṣiṣe awọn ọna asopọ lile lati padanu ati irọrun iwọn-gbogbo lakoko ti o pese awọn agbegbe to buruju. Pagination ti wa ni itumọ pẹlu atokọ HTML awọn eroja ki awọn oluka iboju le kede nọmba awọn ọna asopọ to wa. Lo nkan fifisilẹ <nav>lati ṣe idanimọ rẹ bi apakan lilọ kiri si iboju awọn oluka iboju ati awọn imọ-ẹrọ iranlọwọ miiran.

Ni afikun, bi awọn oju-iwe ṣe le ni diẹ ẹ sii ju ọkan lọ iru apakan lilọ kiri, o ni imọran lati pese apejuwe kan aria-labelfun <nav>lati ṣe afihan idi rẹ. Fun apẹẹrẹ, ti a ba lo paati pagination lati lọ kiri laarin akojọpọ awọn abajade wiwa, aami ti o yẹ le jẹ aria-label="Search results pages".

<nav aria-label="Page navigation example">
  <ul class="pagination">
    <li class="page-item"><a class="page-link" href="#">Previous</a></li>
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item"><a class="page-link" href="#">Next</a></li>
  </ul>
</nav>

Nṣiṣẹ pẹlu awọn aami

Ṣe o n wa lati lo aami tabi aami ni aaye ọrọ fun diẹ ninu awọn ọna asopọ pagination? Rii daju lati pese atilẹyin oluka iboju to dara pẹlu ariaawọn abuda ati ohun .sr-onlyelo naa.

<nav aria-label="Page navigation example">
  <ul class="pagination">
    <li class="page-item">
      <a class="page-link" href="#" aria-label="Previous">
        <span aria-hidden="true">&laquo;</span>
        <span class="sr-only">Previous</span>
      </a>
    </li>
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item">
      <a class="page-link" href="#" aria-label="Next">
        <span aria-hidden="true">&raquo;</span>
        <span class="sr-only">Next</span>
      </a>
    </li>
  </ul>
</nav>

Alaabo ati lọwọ ipinle

Awọn ọna asopọ oju-iwe jẹ asefara fun awọn ipo oriṣiriṣi. Lo .disabledfun awọn ọna asopọ ti o han lai-tẹ ati .activelati tọka oju-iwe lọwọlọwọ.

Lakoko ti .disabledkilasi naa nlo pointer-events: nonelati gbiyanju lati mu iṣẹ ọna asopọ ṣiṣẹ ti <a>s, ohun-ini CSS naa ko tii diwọn ati pe ko ṣe akọọlẹ fun lilọ kiri keyboard. Bii iru bẹẹ, o yẹ ki o ṣafikun nigbagbogbo tabindex="-1"lori awọn ọna asopọ alaabo ati lo JavaScript aṣa lati mu iṣẹ wọn ṣiṣẹ ni kikun.

<nav aria-label="...">
  <ul class="pagination">
    <li class="page-item disabled">
      <a class="page-link" href="#" tabindex="-1">Previous</a>
    </li>
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item active">
      <a class="page-link" href="#">2 <span class="sr-only">(current)</span></a>
    </li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item">
      <a class="page-link" href="#">Next</a>
    </li>
  </ul>
</nav>

O le ni yiyan paarọ awọn ìdákọró ti nṣiṣe lọwọ tabi alaabo fun <span>, tabi fi oran naa silẹ ni ọran ti awọn itọka iṣaaju/tẹle, lati yọ iṣẹ ṣiṣe tẹ kuro ki o ṣe idiwọ idojukọ keyboard lakoko idaduro awọn aṣa ti a pinnu.

<nav aria-label="...">
  <ul class="pagination">
    <li class="page-item disabled">
      <span class="page-link">Previous</span>
    </li>
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item active">
      <span class="page-link">
        2
        <span class="sr-only">(current)</span>
      </span>
    </li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item">
      <a class="page-link" href="#">Next</a>
    </li>
  </ul>
</nav>

Titobi

Fancy tobi tabi kere pagination? Fikun -un .pagination-lgtabi .pagination-smfun awọn iwọn afikun.

<nav aria-label="...">
  <ul class="pagination pagination-lg">
    <li class="page-item disabled">
      <a class="page-link" href="#" tabindex="-1">1</a>
    </li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
  </ul>
</nav>
<nav aria-label="...">
  <ul class="pagination pagination-sm">
    <li class="page-item disabled">
      <a class="page-link" href="#" tabindex="-1">1</a>
    </li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
  </ul>
</nav>

Titete

Yi titete awọn paati pagination pada pẹlu awọn ohun elo flexbox .

<nav aria-label="Page navigation example">
  <ul class="pagination justify-content-center">
    <li class="page-item disabled">
      <a class="page-link" href="#" tabindex="-1">Previous</a>
    </li>
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item">
      <a class="page-link" href="#">Next</a>
    </li>
  </ul>
</nav>
<nav aria-label="Page navigation example">
  <ul class="pagination justify-content-end">
    <li class="page-item disabled">
      <a class="page-link" href="#" tabindex="-1">Previous</a>
    </li>
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item">
      <a class="page-link" href="#">Next</a>
    </li>
  </ul>
</nav>