Source

Navbar

Nā palapala a me nā hiʻohiʻona no ke poʻomanaʻo hoʻokele ikaika a Bootstrap, ka navbar. Loaʻa i ke kākoʻo no ka hōʻailona ʻana, ka hoʻokele ʻana, a me nā mea hou aku, me ke kākoʻo no kā mākou plugin collapse.

Pehea e hana ai

Eia ka mea e pono ai ʻoe e ʻike ma mua o ka hoʻomaka ʻana me ka navbar:

  • Pono nā Navbars i kahi kāʻei .navbarme .navbar-expand{-sm|-md|-lg|-xl}nā papa hāʻule pane a me nā papa kala .
  • ʻO nā Navbars a me kā lākou mau ʻike he wai ma ka paʻamau. E hoʻohana i nā pahu koho e kaupalena i ko lākou ākea ākea.
  • E hoʻohana i kā mākou papa hana hoʻokaʻawale a hoʻololi no ka hoʻomalu ʻana i ka spacing a me ke kaulike ʻana i loko o nā navbars .
  • Hoʻololi nā Navbars ma ka maʻamau, akā hiki iā ʻoe ke hoʻololi maʻalahi iā lākou e hoʻololi i kēlā. ʻO ke ʻano pane e pili ana i kā mākou Collapse JavaScript plugin.
  • Ua hūnā ʻia nā Navbars i ka wā e paʻi ai. E hoʻoikaika iā lākou e paʻi ʻia ma ka hoʻohui .d-printʻana i ka .navbar. E ʻike i ka papa hana hōʻike .
  • E hōʻoia i ka loaʻa ʻana ma o ka hoʻohana ʻana i kahi <nav>mea a i ʻole, inā e hoʻohana ana i kahi mea maʻamau e like me ka <div>, e hoʻohui i kahi role="navigation"i kēlā me kēia navbar e hoʻomaopopo maopopo iā ia he ʻāina ʻāina no nā mea hoʻohana i nā ʻenehana kōkua.

E heluhelu no kahi laʻana a me ka papa inoa o nā ʻāpana i kākoʻo ʻia.

Maʻiʻo i kākoʻo ʻia

Hele mai nā Navbars me ke kākoʻo i kūkulu ʻia no ka liʻiliʻi o nā ʻāpana. E koho mai i ka mea e pono ai:

  • .navbar-brandno kāu hui, huahana, a i ʻole inoa papahana.
  • .navbar-navno ka hoʻokele piha kiʻekiʻe a me ka māmā (me ke kākoʻo no nā hāʻule iho).
  • .navbar-togglerno ka hoʻohana ʻana me kā mākou plugin collapse a me nā ʻano hoʻokele hoʻokele ʻē aʻe .
  • .form-inlineno nā ʻano mana a me nā hana.
  • .navbar-textno ka hoʻohui ʻana i nā kaula kikoʻī o ka kikokikona.
  • .collapse.navbar-collapseno ka hui pū ʻana a me ka hūnā ʻana i nā maʻiʻo o ka navbar e kahi ʻāpana makua.

Eia kekahi laʻana o nā ʻāpana ʻāpana āpau i hoʻokomo ʻia i loko o kahi navbar hoʻonaʻauao māmā e hāʻule ʻakomi i ka wahi haʻi lg(nui).

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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 mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown
        </a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
          <a class="dropdown-item" href="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

Hoʻohana kēia laʻana i nā papa hana kala ( bg-light) a me ka spacing ( my-2, my-lg-0, mr-sm-0, my-sm-0).

Brand

Hiki .navbar-brandke hoʻohana ʻia i ka hapa nui o nā mea, akā ʻoi aku ka maikaʻi o kahi heleuma e like me ke koi ʻana o kekahi mau mea i nā papa pono a i ʻole nā ​​ʻano maʻamau.

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

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

ʻO ka hoʻohui ʻana i nā kiʻi i ke kiʻi e .navbar-brandkoi mau i nā kaila maʻamau a i ʻole nā ​​mea pono i ka nui kūpono. Eia kekahi mau laʻana e hōʻike ai.

<!-- Just an image -->
<nav class="navbar navbar-light bg-light">
  <a class="navbar-brand" href="#">
    <img src="/docs/4.1/assets/brand/bootstrap-solid.svg" width="30" height="30" alt="">
  </a>
</nav>
<!-- Image and text -->
<nav class="navbar navbar-light bg-light">
  <a class="navbar-brand" href="#">
    <img src="/docs/4.1/assets/brand/bootstrap-solid.svg" width="30" height="30" class="d-inline-block align-top" alt="">
    Bootstrap
  </a>
</nav>

Hoʻokumu nā loulou hoʻokele Navbar i kā mākou mau .navkoho me kā lākou papa hoʻololi ponoʻī a koi i ka hoʻohana ʻana i nā papa toggler no ke ʻano pane kūpono. E ulu pū ana ka hoʻokele ma nā navbar e noho i kahi ākea ākea e hiki ai ke hoʻopaʻa paʻa i kāu ʻike navbar.

Hiki ke hoʻohana pololei ʻia nā mokuʻāina ikaika—me— .activee hōʻike i ka ʻaoʻao o kēia manawa iā .nav-links a i ʻole nā ​​mākua .nav-itempili.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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 active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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" href="#">Disabled</a>
      </li>
    </ul>
  </div>
</nav>

A no ka mea ke hoʻohana nei mākou i nā papa no kā mākou navs, hiki iā ʻoe ke pale i ke ala pili i ka papa inoa inā makemake ʻoe.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
      <a class="nav-item nav-link" href="#">Features</a>
      <a class="nav-item nav-link" href="#">Pricing</a>
      <a class="nav-item nav-link disabled" href="#">Disabled</a>
    </div>
  </div>
</nav>

Hiki iā ʻoe ke hoʻohana i nā hāʻule iho i kāu navbar nav. Pono nā menus dropdown i kahi mea hoʻopili no ka hoʻonohonoho ʻana, no laila e hoʻohana pono i nā mea ʻokoʻa a pūnana no .nav-itema .nav-linke like me ka mea i hōʻike ʻia ma lalo nei.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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 active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown link
        </a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
          <a class="dropdown-item" href="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </li>
    </ul>
  </div>
</nav>

Nā palapala

E kau i nā ʻano mana like ʻole a me nā ʻāpana i loko o kahi navbar me .form-inline.

<nav class="navbar navbar-light bg-light">
  <form class="form-inline">
    <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
    <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
  </form>
</nav>

Hoʻohana ʻia nā mea ʻokoʻa o nā keiki i ka .navbarhoʻolālā flex a paʻa i ka justify-content: between. E hoʻohana i nā pono hana maʻalahi e like me ka mea e pono ai e hoʻoponopono i kēia ʻano.

<nav class="navbar navbar-light bg-light">
  <a class="navbar-brand">Navbar</a>
  <form class="form-inline">
    <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
    <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
  </form>
</nav>

Hana pū kekahi pūʻulu hoʻokomo:

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

Kākoʻo ʻia nā pihi like ʻole ma ke ʻano o kēia mau ʻano navbar. He mea hoʻomanaʻo maikaʻi hoʻi kēia e hiki ke hoʻohana ʻia nā pono hana alignment vertical e hoʻohālikelike i nā mea nui like ʻole.

<nav class="navbar navbar-light bg-light">
  <form class="form-inline">
    <button class="btn btn-outline-success" type="button">Main button</button>
    <button class="btn btn-sm btn-outline-secondary" type="button">Smaller button</button>
  </form>
</nav>

kikokikona

Loaʻa i nā Navbars nā ʻāpana kikokikona me ke kōkua o .navbar-text. Hoʻoponopono kēia papa i ka hoʻopololei kū pololei a me ka hoʻokaʻawale ʻana i nā kaula o ke kikokikona.

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

Hoʻohui a hoʻohālikelike me nā mea ʻē aʻe a me nā pono hana e like me ka mea e pono ai.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar w/ text</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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 mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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>
</nav>

Nā kala kala

ʻAʻole i maʻalahi ka hana ʻana i ka navbar ma muli o ka hui pū ʻana o nā papa kumuhana a me background-colornā pono hana. E koho mai .navbar-lightno ka hoʻohana ʻana me nā kala ʻulaʻula, a i ʻole .navbar-darkno nā kala ʻeleʻele. A laila, hoʻonohonoho me .bg-*nā pono hana.

<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>

Nā pahu pahu

ʻOiai ʻaʻole koi ʻia, hiki iā ʻoe ke kāʻei i kahi navbar i kahi .containere hoʻokaʻawale iā ia ma kahi ʻaoʻao a i ʻole e hoʻohui i hoʻokahi i loko e hoʻokomo wale i nā mea o kahi navbar paʻa a paʻa paha .

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

Aia ka pahu i loko o kāu navbar, hoʻoneʻe ʻia kona padding ākea ma nā wahi haʻahaʻa ma lalo o kāu .navbar-expand{-sm|-md|-lg|-xl}papa i kuhikuhi ʻia. ʻO kēia ka mea e hōʻoia ʻaʻole mākou e pāpālua i ka hoʻopaʻa ʻana me ka pono ʻole ma nā wahi nānā haʻahaʻa i ka wā e hiolo ai kāu navbar.

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

Hoʻokomo

E hoʻohana i kā mākou mau pono kūlana e kau i nā navbars i nā kūlana non-static. E koho mai ka hoʻopaʻa ʻana i luna, hoʻopaʻa ʻia i lalo, a i ʻole i hoʻopaʻa ʻia i luna (e ʻōwili me ka ʻaoʻao a hiki i luna, a laila noho ma laila). Hoʻohana ʻia nā navbars paʻa position: fixed, ʻo ia hoʻi, ua huki ʻia lākou mai ke kahe maʻamau o ka DOM a makemake paha i ka CSS maʻamau (e laʻa, padding-topma ka <body>) e pale i ka uhi ʻana me nā mea ʻē aʻe.

E hoʻomaopopo hoʻi i ka .sticky-tophoʻohana ʻana position: sticky, ʻaʻole i kākoʻo piha ʻia i kēlā me kēia polokalamu kele pūnaewele .

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

Nā hana pane

Hiki i nā Navbars ke hoʻohana i .navbar-togglerka , .navbar-collapse, a me .navbar-expand{-sm|-md|-lg|-xl}nā papa e hoʻololi i ka wā e hāʻule ai kā lākou ʻike ma hope o kahi pihi. I ka hui pū ʻana me nā pono hana ʻē aʻe, hiki iā ʻoe ke koho maʻalahi i ka wā e hōʻike ai a hūnā i nā mea kikoʻī.

No nā navbar ʻaʻole e hāʻule, hoʻohui i ka .navbar-expandpapa ma ka navbar. No nā navbar e hāʻule mau ana, mai hoʻohui i kekahi .navbar-expandpapa.

Mea hoʻololi

Hoʻopaʻa ʻia nā mea hoʻololi Navbar ma ke ʻano paʻamau, akā inā e hahai lākou i kahi ʻāpana kaikaina e like me ka .navbar-brand, e hoʻopili ʻia lākou i ka ʻaoʻao ʻākau loa. ʻO ka hoʻohuli ʻana i kāu markup e hoʻohuli i ke kau ʻana o ka mea hoʻololi. Aia ma lalo nā laʻana o nā ʻano hoʻololi like ʻole.

Me ka .navbar-brandhōʻike ʻole ʻia ma kahi haʻahaʻa haʻahaʻa:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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 mr-auto mt-2 mt-lg-0">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

Me ka inoa hōʻailona i hōʻike ʻia ma ka hema a me ka toggle ma ka ʻākau:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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 mr-auto mt-2 mt-lg-0">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

Me ka mea hoʻololi ma ka hema a me ka inoa inoa ma ka ʻākau:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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 mr-auto mt-2 mt-lg-0">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

Maʻiʻo waho

I kekahi manawa makemake ʻoe e hoʻohana i ka plugin collapse e hoʻomaka i ka ʻike huna ma kahi ʻē aʻe ma ka ʻaoʻao. No ka mea e hana ana kā mākou plugin i ka ida me ka data-targethoʻohālikelike ʻana, maʻalahi ia hana!

<div class="pos-f-t">
  <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">
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
  </nav>
</div>