Tīpoka ki te ihirangi matua Tīpoka ki te whakaterenga tuhinga
in English

Navbar

Nga tuhinga me nga tauira mo te pane whakaterenga kaha a Bootstrap, te pae whakaterenga. Kei roto ko te tautoko mo te waitohu, te whakatere, me etahi atu, tae atu ki te tautoko mo to tatou mono tiango.

Pehea te mahi

Anei nga mea e tika ana kia mohio koe i mua i te tiimata i te pae whakatere:

  • Ko nga Navbars e hiahia ana ki te takai .navbarme nga karaehe kaupapa.navbar-expand{-sm|-md|-lg|-xl|-xxl} tiango aro me nga karaehe.
  • Navbars me o ratou ihirangi he wai ma te taunoa. Hurihia te ipu hei whakawhāiti i te whanui whakapae ma nga huarahi rereke.
  • Whakamahia a maatau akomanga whaipainga mokowhiti me te ngawari mo te whakahaere i te mokowā me te tirohanga i roto i nga pae whakatere.
  • Ko nga Navbars he whakautu taunoa, engari ka taea e koe te whakarereke i a raatau ki te whakarereke i tera. Ko te whanonga urupare kei runga i ta maatau mono Tiango JavaScript.
  • Whakaritea te urunga ma te whakamahi i tetahi <nav>huānga, ki te whakamahi ranei i tetahi huānga nui ake penei i te <div>, taapirihia he role="navigation"ki ia pae whakatere kia tino mohio ai hei rohe tohu whenua mo nga kaiwhakamahi hangarau awhina.
  • Tohua te tuemi o naianei ma te whakamahi aria-current="page"mo te wharangi o naianei, aria-current="true"mo te taonga onāianei ranei i roto i te huinga.
Ko te awe hākoritanga o tēnei wāhanga e whakawhirinaki ana ki te prefers-reduced-motionuiui pāpāho. Tirohia te waahanga motini whakaheke o a maatau tuhinga whakaurunga .

Ihirangi tautoko

Ka tae mai nga Navbars me te tautoko i hangaia mo etahi waahanga iti. Whiriwhiria mai i nga mea e whai ake nei ina hiahiatia:

  • .navbar-brandmo to kamupene, hua, ingoa kaupapa ranei.
  • .navbar-navmo te whakaterenga teitei me te maamaa (tae atu ki te tautoko mo nga takaiho).
  • .navbar-togglerhei whakamahi me to tatou mono tiango me etahi atu whanonga takahuri whakatere .
  • Nga taputapu whakaheke me te mokowhiti mo nga momo mana me nga mahi.
  • .navbar-textmo te taapiri i nga aho poutū o te kuputuhi.
  • .collapse.navbar-collapsemo te whakarōpū me te huna i nga ihirangi pae whakatere ma te waahi wehenga matua.
  • Tāpirihia he kōwhiringa .navbar-scrollki te tautuhi max-heightme te panuku i te ihirangi pae whakatere kua whakawhānuihia .

Anei he tauira o nga waahanga-iti katoa kei roto i te pae whakaterenga-a-marama ka tiango aunoa i te lgwaahi (nui).

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            Dropdown
          </a>
          <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
            <li><a class="dropdown-item" href="#">Action</a></li>
            <li><a class="dropdown-item" href="#">Another action</a></li>
            <li><hr class="dropdown-divider"></li>
            <li><a class="dropdown-item" href="#">Something else here</a></li>
          </ul>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled">Disabled</a>
        </li>
      </ul>
      <form class="d-flex">
        <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
        <button class="btn btn-outline-success" type="submit">Search</button>
      </form>
    </div>
  </div>
</nav>

Ka whakamahia e tenei tauira nga papamuri ( bg-light) me te mokowhiti ( my-2, my-lg-0, me-sm-0, my-sm-0) akomanga whaipainga.

Waitohu

Ka .navbar-brandtaea te tono ki te nuinga o nga huānga, engari he pai te mahi o te punga, na te mea ka hiahia etahi o nga huānga ki nga karaehe whaipainga, ki nga momo ritenga ranei.

Kuputuhi

Tāpirihia to kuputuhi ki roto i tetahi huānga me te .navbar-brandakomanga.

<!-- As a link -->
<nav class="navbar navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar</a>
  </div>
</nav>

<!-- As a heading -->
<nav class="navbar navbar-light bg-light">
  <div class="container-fluid">
    <span class="navbar-brand mb-0 h1">Navbar</span>
  </div>
</nav>

Whakaahua

Ka taea e koe te whakakapi i te kuputuhi i roto i te .navbar-brandki te <img>.

<nav class="navbar navbar-light bg-light">
  <div class="container">
    <a class="navbar-brand" href="#">
      <img src="/docs/5.1/assets/brand/bootstrap-logo.svg" alt="" width="30" height="24">
    </a>
  </div>
</nav>

Whakaahua me te tuhinga

Ka taea hoki e koe te whakamahi i etahi taputapu taapiri hei taapiri i tetahi ahua me te tuhinga i te wa ano. Tuhia te taapiri o te .d-inline-blockme .align-text-toprunga i te <img>.

<nav class="navbar navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">
      <img src="/docs/5.1/assets/brand/bootstrap-logo.svg" alt="" width="30" height="24" class="d-inline-block align-text-top">
      Bootstrap
    </a>
  </div>
</nav>

Ko nga hononga whakatere Navbar e hanga ana i runga i o maatau .navwhiringa me o raatau ake karaehe whakarereke, me te whakamahi i nga karaehe takahuri mo te whakaahua tika. Ka tipu ano te whakaterenga i roto i nga pae whakatere ki te noho i te mokowā whakapae kia noho tika ai to ihirangi pae whakatere.

Tāpirihia te .activeakomanga .nav-linkhei tohu i te wharangi o naianei.

Kia mahara me taapiri ano te aria-currenthuanga ki te hohe .nav-link.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
      <ul class="navbar-nav">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Features</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Pricing</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled">Disabled</a>
        </li>
      </ul>
    </div>
  </div>
</nav>

A, na te mea ka whakamahia e matou nga karaehe mo o maatau whakatere, ka taea e koe te karo i te huarahi e pa ana ki te raarangi mena ka pai koe.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
      <div class="navbar-nav">
        <a class="nav-link active" aria-current="page" href="#">Home</a>
        <a class="nav-link" href="#">Features</a>
        <a class="nav-link" href="#">Pricing</a>
        <a class="nav-link disabled">Disabled</a>
      </div>
    </div>
  </div>
</nav>

Ka taea hoki e koe te whakamahi i nga takaiho i to pae whakatere. Ko nga tahua takaiho e hiahia ana he huānga takai mo te tuunga, no reira kia mohio koe ki te whakamahi i nga huānga motuhake me te kohanga mo .nav-item, .nav-linkme te whakaatu i raro nei.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNavDropdown">
      <ul class="navbar-nav">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Features</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Pricing</a>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            Dropdown link
          </a>
          <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
            <li><a class="dropdown-item" href="#">Action</a></li>
            <li><a class="dropdown-item" href="#">Another action</a></li>
            <li><a class="dropdown-item" href="#">Something else here</a></li>
          </ul>
        </li>
      </ul>
    </div>
  </div>
</nav>

Puka

Whakanohoia nga momo mana me nga waahanga ki roto i te pae whakatere:

<nav class="navbar navbar-light bg-light">
  <div class="container-fluid">
    <form class="d-flex">
      <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success" type="submit">Search</button>
    </form>
  </div>
</nav>

Ko nga huānga tamariki tonu o te .navbarwhakamahi tahora ngawari ka taunoa ki justify-content: space-between. Whakamahia etahi atu taputapu ngawari ina hiahiatia hei whakatika i tenei whanonga.

<nav class="navbar navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand">Navbar</a>
    <form class="d-flex">
      <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success" type="submit">Search</button>
    </form>
  </div>
</nav>

Ka mahi ano nga roopu whakauru. Mena he ahua katoa to pae whakatere, he puka te nuinga ranei, ka taea e koe te whakamahi i te <form>huānga hei ipu me te tiaki i etahi HTML.

<nav class="navbar navbar-light bg-light">
  <form class="container-fluid">
    <div class="input-group">
      <span class="input-group-text" id="basic-addon1">@</span>
      <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1">
    </div>
  </form>
</nav>

He maha nga patene e tautokohia ana hei waahanga o enei puka navbar. He whakamaumahara pai tenei ka taea te whakamahi i nga taputapu tirohanga poutū ki te whakahāngai i nga huānga o te rahi.

<nav class="navbar navbar-light bg-light">
  <form class="container-fluid justify-content-start">
    <button class="btn btn-outline-success me-2" type="button">Main button</button>
    <button class="btn btn-sm btn-outline-secondary" type="button">Smaller button</button>
  </form>
</nav>

Kuputuhi

Kei roto pea i nga Navbars etahi moka kuputuhi me te awhina o .navbar-text. Ka whakatikahia e tenei akomanga te tirohanga poutū me te mokowhiti whakapae mo nga aho o te kuputuhi.

<nav class="navbar navbar-light bg-light">
  <div class="container-fluid">
    <span class="navbar-text">
      Navbar text with an inline element
    </span>
  </div>
</nav>

Whakaranuhia me te whakakotahi ki etahi atu waahanga me nga taputapu ka hiahiatia.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar w/ text</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarText">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Features</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Pricing</a>
        </li>
      </ul>
      <span class="navbar-text">
        Navbar text with an inline element
      </span>
    </div>
  </div>
</nav>

Kaupapa tae

Ko te whakamaarama i te pae navbar kaore ano kia ngawari ake na te whakakotahitanga o nga karaehe kaupapa me nga background-colortaputapu. Whiriwhiria .navbar-lighthei whakamahi me nga tae papamuri marama, .navbar-darkmo nga tae papamuri pouri ranei. Na, whakarite me nga .bg-*taputapu.

<nav class="navbar navbar-dark bg-dark">
  <!-- Navbar content -->
</nav>

<nav class="navbar navbar-dark bg-primary">
  <!-- Navbar content -->
</nav>

<nav class="navbar navbar-light" style="background-color: #e3f2fd;">
  <!-- Navbar content -->
</nav>

Nga ipu

Ahakoa karekau e hiahiatia, ka taea e koe te takai i te pae whakatere ki roto .containeri tetahi wharangi kia whakakotahitia ki te wharangi–ahakoa me mahara tonu kei te hiahiatia he ipu o roto. Ka taea ranei e koe te taapiri i tetahi ipu ki roto .navbarki te whakauru noa i nga ihirangi o te pae whakaterenga o runga pumau ranei .

<div class="container">
  <nav class="navbar navbar-expand-lg navbar-light bg-light">
    <div class="container-fluid">
      <a class="navbar-brand" href="#">Navbar</a>
    </div>
  </nav>
</div>

Whakamahia tetahi o nga ipu aro ki te whakarereke i te whanui o nga ihirangi kei roto i to pae whakatere.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-md">
    <a class="navbar-brand" href="#">Navbar</a>
  </div>
</nav>

Whakanoho

Whakamahia a maatau taputapu tuunga hei tuu i nga pae whakatere ki nga waahi kore-pateko. Kōwhiria mai i te pūmau ki runga, ka mau ki raro, ka piri ranei ki runga (panuku me te wharangi tae noa ki runga, ka noho ki reira). Ka whakamahia e nga navbars position: fixed, te tikanga ka toia mai i te rere noa o te DOM me te hiahia CSS ritenga (hei tauira, padding-topi runga i te <body>) kia kore ai e inaki ki etahi atu huānga.

Kia mahara hoki ko .sticky-topnga whakamahinga position: sticky, kaore i te tino tautokona i ia kaitirotiro .

<nav class="navbar navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Default</a>
  </div>
</nav>
<nav class="navbar fixed-top navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Fixed top</a>
  </div>
</nav>
<nav class="navbar fixed-bottom navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Fixed bottom</a>
  </div>
</nav>
<nav class="navbar sticky-top navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Sticky top</a>
  </div>
</nav>

Panuku

Tāpirihia .navbar-nav-scrollki tetahi .navbar-nav(tetahi atu waahanga-iti ranei) kia taea ai te panuku poutū i roto i nga ihirangi ka taea te takahuri o te pae whakaterenga kua tiango. Ma te taunoa, ka whana te panuku ki roto i te 75vh(75% ranei o te teitei tauranga tirohanga), engari ka taea e koe te whakakore i tera me nga rawa ritenga CSS rohe --bs-navbar-height, momo ritenga ranei. I nga tauranga tirohanga nui ake ina whakaroahia te paewhakatua, ka puta nga ihirangi penei i te pae whakaterenga taunoa.

Kia mahara ko tenei whanonga ka tae mai me te ngoikoretanga o te overflow—ka tautuhi overflow-y: auto(he mea tika kia panuku te ihirangi ki konei), overflow-xhe rite ki te auto, ka tapahia etahi ihirangi whakapae.

Anei tetahi tauira navbar e whakamahi ana .navbar-nav-scrollme te style="--bs-scroll-height: 100px;", me etahi taputapu taapiri taapiri mo te mokowhiti tino pai.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar scroll</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarScroll" aria-controls="navbarScroll" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarScroll">
      <ul class="navbar-nav me-auto my-2 my-lg-0 navbar-nav-scroll" style="--bs-scroll-height: 100px;">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarScrollingDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            Link
          </a>
          <ul class="dropdown-menu" aria-labelledby="navbarScrollingDropdown">
            <li><a class="dropdown-item" href="#">Action</a></li>
            <li><a class="dropdown-item" href="#">Another action</a></li>
            <li><hr class="dropdown-divider"></li>
            <li><a class="dropdown-item" href="#">Something else here</a></li>
          </ul>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled">Link</a>
        </li>
      </ul>
      <form class="d-flex">
        <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
        <button class="btn btn-outline-success" type="submit">Search</button>
      </form>
    </div>
  </div>
</nav>

Nga whanonga urupare

Ka taea e nga Navbars te whakamahi i te .navbar-toggler, .navbar-collapse, me .navbar-expand{-sm|-md|-lg|-xl|-xxl}nga karaehe ki te whakatau i te wa e tiango ai o raatau ihirangi ki muri i te paatene. Ma te whakakotahi me etahi atu taputapu, ka taea e koe te whiriwhiri i te wa e whakaatu ai, e huna ana ranei i etahi waahanga.

Mo nga pae whakatere e kore e tiango, taapirihia te .navbar-expandkaraehe ki te pae whakatere. Mo nga pae whakatere ka tiango i nga wa katoa, kaua e taapirihia he .navbar-expandkaraehe.

Kaihurihuri

Ko nga kaihurihuri Navbar kua tiaro-maui ma te taunoa, engari mena ka whai ratou i tetahi huānga teina penei i te .navbar-brand, ka tiaaro aunoa ki te taha matau. Ma te whakahuri i to tohu ka whakataka te tuunga o te kaihurihuri. Kei raro nei nga tauira o nga momo takahuri rereke.

Ki te kore e .navbar-brandwhakaatuhia i te waahi pakaru iti rawa:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarTogglerDemo01">
      <a class="navbar-brand" href="#">Hidden brand</a>
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled">Disabled</a>
        </li>
      </ul>
      <form class="d-flex">
        <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
        <button class="btn btn-outline-success" type="submit">Search</button>
      </form>
    </div>
  </div>
</nav>

Me te ingoa tohu kei te taha maui me te takahuri kei te taha matau:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarTogglerDemo02">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled">Disabled</a>
        </li>
      </ul>
      <form class="d-flex">
        <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
        <button class="btn btn-outline-success" type="submit">Search</button>
      </form>
    </div>
  </div>
</nav>

Me te takahuri kei te taha maui me te ingoa waitohu kei te taha matau:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo03" aria-controls="navbarTogglerDemo03" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <a class="navbar-brand" href="#">Navbar</a>
    <div class="collapse navbar-collapse" id="navbarTogglerDemo03">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled">Disabled</a>
        </li>
      </ul>
      <form class="d-flex">
        <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
        <button class="btn btn-outline-success" type="submit">Search</button>
      </form>
    </div>
  </div>
</nav>

Ihirangi o waho

I etahi wa ka hiahia koe ki te whakamahi i te mono tiango hei whakaoho i tetahi huānga ipu mo nga ihirangi e noho ana ki waho o te .navbar. Na te mea e mahi ana ta maatau mono i runga i te idme data-bs-targette taurite, he ngawari te mahi!

<div class="collapse" id="navbarToggleExternalContent">
  <div class="bg-dark p-4">
    <h5 class="text-white h4">Collapsed content</h5>
    <span class="text-muted">Toggleable via the navbar brand.</span>
  </div>
</div>
<nav class="navbar navbar-dark bg-dark">
  <div class="container-fluid">
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
  </div>
</nav>

Ina mahi koe i tenei, ka tūtohu kia whakaurua etahi atu JavaScript hei nuku i te arotahi ki te ipu ina whakatuwheratia. Ki te kore, ka uaua nga kaiwhakamahi papapātuhi me nga kaiwhakamahi hangarau awhina ki te rapu i nga ihirangi hou - ina koa ka tae mai te ipu i whakatuwherahia ki mua i te takahuri i te hanganga o te tuhinga. Ka tūtohu ano matou kia mohio kei te takahuri te aria-controlshuanga, tohu ki te ido te ipu ihirangi. I roto i te ariā, ma tenei ka taea e nga kaiwhakamahi hangarau awhina te peke tika mai i te takahuri ki te ipu e whakahaeretia ana e ia–engari ko te tautoko mo tenei he tino pahekeheke.

Kowekeweke

Hurihia to pae toronga whakaroa me te tiango ki roto i te pouaka whakaata me te mono o waho. Ka whakawhānuihia e matou nga momo ahua taunoa o waho me te whakamahi i o maatau .navbar-expand-*karaehe ki te hanga i tetahi paetaha whakatere hihiri me te ngawari.

I roto i te tauira i raro nei, ki te hanga i tetahi pae whakaterenga o waho e tiango ana puta noa i nga waahi wehenga katoa, waiho .navbar-expand-*katoatia te karaehe.

<nav class="navbar navbar-light bg-light fixed-top">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Offcanvas navbar</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasNavbar" aria-controls="offcanvasNavbar">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasNavbar" aria-labelledby="offcanvasNavbarLabel">
      <div class="offcanvas-header">
        <h5 class="offcanvas-title" id="offcanvasNavbarLabel">Offcanvas</h5>
        <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
      </div>
      <div class="offcanvas-body">
        <ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
          <li class="nav-item">
            <a class="nav-link active" aria-current="page" href="#">Home</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">Link</a>
          </li>
          <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" id="offcanvasNavbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
              Dropdown
            </a>
            <ul class="dropdown-menu" aria-labelledby="offcanvasNavbarDropdown">
              <li><a class="dropdown-item" href="#">Action</a></li>
              <li><a class="dropdown-item" href="#">Another action</a></li>
              <li>
                <hr class="dropdown-divider">
              </li>
              <li><a class="dropdown-item" href="#">Something else here</a></li>
            </ul>
          </li>
        </ul>
        <form class="d-flex">
          <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
          <button class="btn btn-outline-success" type="submit">Search</button>
        </form>
      </div>
    </div>
  </div>
</nav>

Hei hanga i tetahi pae whakaterenga o waho ka toro atu ki te pae whakaterenga noa i te waahi wehenga motuhake penei lg, whakamahia .navbar-expand-lg.

<nav class="navbar navbar-light navbar-expand-lg bg-light fixed-top">
  <a class="navbar-brand" href="#">Offcanvas navbar</a>
  <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#navbarOffcanvasLg" aria-controls="navbarOffcanvasLg">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="offcanvas offcanvas-end" tabindex="-1" id="navbarOffcanvasLg" aria-labelledby="navbarOffcanvasLgLabel">
    ...
  </div>
</nav>

Sass

Taurangi

$navbar-padding-y:                  $spacer * .5;
$navbar-padding-x:                  null;

$navbar-nav-link-padding-x:         .5rem;

$navbar-brand-font-size:            $font-size-lg;
// Compute the navbar-brand padding-y so the navbar-brand will have the same height as navbar-text and nav-link
$nav-link-height:                   $font-size-base * $line-height-base + $nav-link-padding-y * 2;
$navbar-brand-height:               $navbar-brand-font-size * $line-height-base;
$navbar-brand-padding-y:            ($nav-link-height - $navbar-brand-height) * .5;
$navbar-brand-margin-end:           1rem;

$navbar-toggler-padding-y:          .25rem;
$navbar-toggler-padding-x:          .75rem;
$navbar-toggler-font-size:          $font-size-lg;
$navbar-toggler-border-radius:      $btn-border-radius;
$navbar-toggler-focus-width:        $btn-focus-width;
$navbar-toggler-transition:         box-shadow .15s ease-in-out;
$navbar-dark-color:                 rgba($white, .55);
$navbar-dark-hover-color:           rgba($white, .75);
$navbar-dark-active-color:          $white;
$navbar-dark-disabled-color:        rgba($white, .25);
$navbar-dark-toggler-icon-bg:       url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke='#{$navbar-dark-color}' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg>");
$navbar-dark-toggler-border-color:  rgba($white, .1);

$navbar-light-color:                rgba($black, .55);
$navbar-light-hover-color:          rgba($black, .7);
$navbar-light-active-color:         rgba($black, .9);
$navbar-light-disabled-color:       rgba($black, .3);
$navbar-light-toggler-icon-bg:      url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke='#{$navbar-light-color}' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg>");
$navbar-light-toggler-border-color: rgba($black, .1);

$navbar-light-brand-color:                $navbar-light-active-color;
$navbar-light-brand-hover-color:          $navbar-light-active-color;
$navbar-dark-brand-color:                 $navbar-dark-active-color;
$navbar-dark-brand-hover-color:           $navbar-dark-active-color;

Porowhita

Ko nga karaehe whakawhänui/tiango whakautu (hei tauira, .navbar-expand-lg) ka honoa ki te $breakpointsmapi, ka hangaia ma te kopikopiko i roto scss/_navbar.scss.

// Generate series of `.navbar-expand-*` responsive classes for configuring
// where your navbar collapses.
.navbar-expand {
  @each $breakpoint in map-keys($grid-breakpoints) {
    $next: breakpoint-next($breakpoint, $grid-breakpoints);
    $infix: breakpoint-infix($next, $grid-breakpoints);

    // stylelint-disable-next-line scss/selector-no-union-class-name
    &#{$infix} {
      @include media-breakpoint-up($next) {
        flex-wrap: nowrap;
        justify-content: flex-start;

        .navbar-nav {
          flex-direction: row;

          .dropdown-menu {
            position: absolute;
          }

          .nav-link {
            padding-right: $navbar-nav-link-padding-x;
            padding-left: $navbar-nav-link-padding-x;
          }
        }

        .navbar-nav-scroll {
          overflow: visible;
        }

        .navbar-collapse {
          display: flex !important; // stylelint-disable-line declaration-no-important
          flex-basis: auto;
        }

        .navbar-toggler {
          display: none;
        }

        .offcanvas-header {
          display: none;
        }

        .offcanvas {
          position: inherit;
          bottom: 0;
          z-index: 1000;
          flex-grow: 1;
          visibility: visible !important; // stylelint-disable-line declaration-no-important
          background-color: transparent;
          border-right: 0;
          border-left: 0;
          @include transition(none);
          transform: none;
        }
        .offcanvas-top,
        .offcanvas-bottom {
          height: auto;
          border-top: 0;
          border-bottom: 0;
        }

        .offcanvas-body {
          display: flex;
          flex-grow: 0;
          padding: 0;
          overflow-y: visible;
        }
      }
    }
  }
}