docs-navbar.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>jQuery Mobile Docs - Navbar</title>
  7. <link rel="stylesheet" href="../../jquery.mobile-1.0.1.min.css" />
  8. <link rel="stylesheet" href="../_assets/css/jqm-docs.css"/>
  9. <script src="../../jquery.js"></script>
  10. <script src="../../experiments/themeswitcher/jquery.mobile.themeswitcher.js"></script>
  11. <script src="../_assets/js/jqm-docs.js"></script>
  12. <script src="../../jquery.mobile-1.0.1.min.js"></script>
  13. </head>
  14. <body>
  15. <div data-role="page" class="type-interior">
  16. <div data-role="header" data-theme="f">
  17. <h1>Navbar</h1>
  18. <a href="../../" data-icon="home" data-iconpos="notext" data-direction="reverse" class="ui-btn-right jqm-home">Home</a>
  19. </div><!-- /header -->
  20. <div data-role="content">
  21. <div class="content-primary">
  22. <h2>Simple navbar</h2>
  23. <p>jQuery Mobile has a very basic navbar widget that is useful for providing up to 5 buttons with optional icons in a bar, typically within a header or footer. There is also a <a href="footer-persist-a.html">persistent navbar</a> variation that works more like a tab bar that stays fixed as you navigate across pages.</p>
  24. <p>A navbar is coded as an unordered list of links wrapped in a container element that has the <code> data-role="navbar"</code> attribute. To set one of links to the active (selected) state, add <code>class="ui-btn-active"</code> to the anchor. In this example, we have a two-button navbar in the footer with the "One" item set to active:</p>
  25. <pre><code>
  26. <strong>&lt;div data-role=&quot;navbar&quot;&gt;</strong>
  27. &lt;ul&gt;
  28. &lt;li&gt;&lt;a href=&quot;a.html&quot; class=&quot;ui-btn-active&quot;&gt;One&lt;/a&gt;&lt;/li&gt;
  29. &lt;li&gt;&lt;a href=&quot;b.html&quot;&gt;Two&lt;/a&gt;&lt;/li&gt;
  30. &lt;/ul&gt;
  31. <strong>&lt;/div&gt;&lt;!-- /navbar --&gt;</strong>
  32. </code></pre>
  33. <p>The navbar items are set to divide the space evenly so in this case, each button is 1/2 the width of the browser window:</p>
  34. <div data-role="navbar">
  35. <ul>
  36. <li><a href="#" class="ui-btn-active">One</a></li>
  37. <li><a href="#">Two</a></li>
  38. </ul>
  39. </div><!-- /navbar -->
  40. <p>Adding a third item will automatically make each button 1/3 the width of the browser window:</p>
  41. <div data-role="navbar">
  42. <ul>
  43. <li><a href="#" class="ui-btn-active">One</a></li>
  44. <li><a href="#">Two</a></li>
  45. <li><a href="#">Three</a></li>
  46. </ul>
  47. </div><!-- /navbar -->
  48. <p>Adding a fourth more item will automatically make each button 1/4 the width of the browser window:</p>
  49. <div data-role="navbar" data-grid="c">
  50. <ul>
  51. <li><a href="#" class="ui-btn-active">One</a></li>
  52. <li><a href="#">Two</a></li>
  53. <li><a href="#">Three</a></li>
  54. <li><a href="#">Four</a></li>
  55. </ul>
  56. </div><!-- /navbar -->
  57. <p>The navbar maxes out with 5 items, each 1/5 the width of the browser window:</p>
  58. <div data-role="navbar" data-grid="d">
  59. <ul>
  60. <li><a href="#" class="ui-btn-active">One</a></li>
  61. <li><a href="#">Two</a></li>
  62. <li><a href="#">Three</a></li>
  63. <li><a href="#">Four</a></li>
  64. <li><a href="#">Five</a></li>
  65. </ul>
  66. </div><!-- /navbar -->
  67. <p>If more than 5 items are added, the navbar will simply wrap to multiple lines:</p>
  68. <div data-role="navbar">
  69. <ul>
  70. <li><a href="#" class="ui-btn-active">One</a></li>
  71. <li><a href="#">Two</a></li>
  72. <li><a href="#">Three</a></li>
  73. <li><a href="#">Four</a></li>
  74. <li><a href="#">Five</a></li>
  75. <li><a href="#">Six</a></li>
  76. <li><a href="#">Seven</a></li>
  77. <li><a href="#">Eight</a></li>
  78. <li><a href="#">Nine</a></li>
  79. <li><a href="#">Ten</a></li>
  80. </ul>
  81. </div><!-- /navbar -->
  82. <p>As a fallback, navbars with 1 item will simply render as 100%.</p>
  83. <div data-role="navbar">
  84. <ul>
  85. <li><a href="#" class="ui-btn-active">One</a></li>
  86. </ul>
  87. </div><!-- /navbar -->
  88. <h2>Navbars in headers</h2>
  89. <p>If you want to add a navbar to the top of the page, you can still have a page title and buttons. Just add the navbar container inside the header block, right after the title and buttons in the source order.</p>
  90. <div data-role="header">
  91. <h1>I'm a header</h1>
  92. <a href="index.html" data-icon="gear" class="ui-btn-right">Options</a>
  93. <div data-role="navbar">
  94. <ul>
  95. <li><a href="#">One</a></li>
  96. <li><a href="#">Two</a></li>
  97. <li><a href="#">Three</a></li>
  98. </ul>
  99. </div><!-- /navbar -->
  100. </div><!-- /header -->
  101. <h2>Navbars in footers</h2>
  102. <p>If you want to add a navbar to the bottom of the page so it acts more like a tab bar, simply wrap the navbar in a container with a <code>data-role="footer"</code></p>
  103. <pre><code>
  104. &lt;div data-role=&quot;footer&quot;&gt;
  105. &lt;div data-role=&quot;navbar&quot;&gt;
  106. &lt;ul&gt;
  107. &lt;li&gt;&lt;a href=&quot;#&quot;&gt;One&lt;/a&gt;&lt;/li&gt;
  108. &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Two&lt;/a&gt;&lt;/li&gt;
  109. &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Three&lt;/a&gt;&lt;/li&gt;
  110. &lt;/ul&gt;
  111. &lt;/div&gt;&lt;!-- /navbar --&gt;
  112. &lt;/div&gt;&lt;!-- /footer --&gt;
  113. </code></pre>
  114. <div data-role="footer">
  115. <div data-role="navbar">
  116. <ul>
  117. <li><a href="#">One</a></li>
  118. <li><a href="#">Two</a></li>
  119. <li><a href="#">Three</a></li>
  120. </ul>
  121. </div><!-- /navbar -->
  122. </div><!-- /footer -->
  123. <h2>Icons in navbars</h2>
  124. <p>Icons can be added to navbar items by adding the <code> data-icon</code> attribute specifying a <a href="../buttons/buttons-icons.html">standard mobile icon</a> to each anchor. By default, icons are added above the text (<code>data-iconpos="top"</code>). The following examples add icons to a navbar in a footer.</p>
  125. <div data-role="footer">
  126. <div data-role="navbar">
  127. <ul>
  128. <li><a href="#" data-icon="grid">Summary</a></li>
  129. <li><a href="#" data-icon="star" class="ui-btn-active">Favs</a></li>
  130. <li><a href="#" data-icon="gear">Setup</a></li>
  131. </ul>
  132. </div><!-- /navbar -->
  133. </div><!-- /footer -->
  134. <p>The icon position is set <em>on the navbar container</em> instead of for individual links within for visual consistency. For example, to place the icons below the labels, add the <code> data-iconpos="bottom"</code> attribute to the navbar container.</p>
  135. <pre><code>
  136. &lt;div data-role=&quot;navbar&quot; <strong>data-iconpos=&quot;bottom&quot;</strong>&gt;
  137. </code></pre>
  138. <p>This will result in a bottom icon alignment:</p>
  139. <div data-role="footer">
  140. <div data-role="navbar" data-iconpos="bottom">
  141. <ul>
  142. <li><a href="#" data-icon="grid">Summary</a></li>
  143. <li><a href="#" data-icon="star" class="ui-btn-active">Favs</a></li>
  144. <li><a href="#" data-icon="gear">Setup</a></li>
  145. </ul>
  146. </div><!-- /navbar -->
  147. </div><!-- /footer -->
  148. <p>The icon position can be set to <code>data-iconpos="left"</code>:</p>
  149. <div data-role="footer">
  150. <div data-role="navbar" data-iconpos="left">
  151. <ul>
  152. <li><a href="#" data-icon="grid">Summary</a></li>
  153. <li><a href="#" data-icon="star" class="ui-btn-active">Favs</a></li>
  154. <li><a href="#" data-icon="gear">Setup</a></li>
  155. </ul>
  156. </div><!-- /navbar -->
  157. </div><!-- /footer -->
  158. <p>Or the icon position can be set to <code>data-iconpos="right"</code>:</p>
  159. <div data-role="footer">
  160. <div data-role="navbar" data-iconpos="right">
  161. <ul>
  162. <li><a href="#" data-icon="grid">Summary</a></li>
  163. <li><a href="#" data-icon="star" class="ui-btn-active">Favs</a></li>
  164. <li><a href="#" data-icon="gear">Setup</a></li>
  165. </ul>
  166. </div><!-- /navbar -->
  167. </div><!-- /footer -->
  168. <h2>Using 3rd party icon sets</h2>
  169. <p>You can add any of the popular icon libraries like <a href="http://glyphish.com/">Glyphish</a> to achieve the iOS style tab that has large icons stacked on top of text labels. All that is required is a bit of custom styles to link to the icons and position them in the navbar. Here is an example using Glyphish icons and custom styles (view page source for styles) in our navbar:</p>
  170. <style>
  171. .nav-glyphish-example .ui-btn .ui-btn-inner { padding-top: 40px !important; }
  172. .nav-glyphish-example .ui-btn .ui-icon { width: 30px!important; height: 30px!important; margin-left: -15px !important; box-shadow: none!important; -moz-box-shadow: none!important; -webkit-box-shadow: none!important; -webkit-border-radius: 0 !important; border-radius: 0 !important; }
  173. #chat .ui-icon { background: url(glyphish-icons/09-chat2.png) 50% 50% no-repeat; background-size: 24px 22px; }
  174. #email .ui-icon { background: url(glyphish-icons/18-envelope.png) 50% 50% no-repeat; background-size: 24px 16px; }
  175. #login .ui-icon { background: url(glyphish-icons/30-key.png) 50% 50% no-repeat; background-size: 12px 26px; }
  176. #beer .ui-icon { background: url(glyphish-icons/88-beermug.png) 50% 50% no-repeat; background-size: 22px 27px; }
  177. #coffee .ui-icon { background: url(glyphish-icons/100-coffee.png) 50% 50% no-repeat; background-size: 20px 24px; }
  178. #skull .ui-icon { background: url(glyphish-icons/21-skull.png) 50% 50% no-repeat; background-size: 22px 24px; }
  179. </style>
  180. <div data-role="footer" class="nav-glyphish-example">
  181. <div data-role="navbar" class="nav-glyphish-example" data-grid="d">
  182. <ul>
  183. <li><a href="#" id="chat" data-icon="custom">Chat</a></li>
  184. <li><a href="#" id="email" data-icon="custom">Email</a></li>
  185. <li><a href="#" id="skull" data-icon="custom">Danger</a></li>
  186. <li><a href="#" id="beer" data-icon="custom">Beer</a></li>
  187. <li><a href="#" id="coffee" data-icon="custom">Coffee</a></li>
  188. </ul>
  189. </div>
  190. </div>
  191. <p>Icons by Joseph Wain / <a href="http://glyphish.com/">glyphish.com</a>. Licensed under the <a href="http://creativecommons.org/licenses/by/3.0/us/">Creative Commons Attribution 3.0 United States License</a>.</p>
  192. <h2>Theming navbars</h2>
  193. <p>Navbars inherit the theme swatch from their parent container, just like buttons. If a navbar is placed in the header or footer toolbar, it will inherit the default toolbar swatch (A) for bars unless you set this in the markup. </p>
  194. <p>Here are a few examples of navbars in various container swatches that automatically inheriting their parent's swatch letter. Note that in these examples, instead of using a <code>data-theme</code> attribute, we're manually adding the swatch classes to apply the body swatch (<code>ui-body-a</code>) and the class to add the standard body padding (ui-body), but the inheritance works the same way:</p>
  195. <div class="ui-body-a ui-body">
  196. <h3>Swatch A</h3>
  197. <div data-role="navbar">
  198. <ul>
  199. <li><a href="#" data-icon="grid">A</a></li>
  200. <li><a href="#" data-icon="star">B</a></li>
  201. <li><a href="#" data-icon="gear">C</a></li>
  202. <li><a href="#" data-icon="arrow-l">D</a></li>
  203. <li><a href="#" data-icon="arrow-r">E</a></li>
  204. </ul>
  205. </div><!-- /navbar -->
  206. </div><!-- /container -->
  207. <div class="ui-body-d ui-body">
  208. <h3>Swatch B</h3>
  209. <div data-role="navbar">
  210. <ul>
  211. <li><a href="#" data-icon="grid">A</a></li>
  212. <li><a href="#" data-icon="star">B</a></li>
  213. <li><a href="#" data-icon="gear">C</a></li>
  214. <li><a href="#" data-icon="arrow-l">D</a></li>
  215. <li><a href="#" data-icon="arrow-r">E</a></li>
  216. </ul>
  217. </div><!-- /navbar -->
  218. </div><!-- /container -->
  219. <p>To set to the theme color for a navbar item, add the <code>data-theme</code> attribute to the individual links and specify a theme swatch. Note that applying a theme swatch to the navbar container is <em>not</em> supported.</p>
  220. <div data-role="footer">
  221. <div data-role="navbar">
  222. <ul>
  223. <li><a href="#" data-icon="grid"data-theme="a">A</a></li>
  224. <li><a href="#" data-icon="star" data-theme="b">B</a></li>
  225. <li><a href="#" data-icon="gear" data-theme="c">C</a></li>
  226. <li><a href="#" data-icon="arrow-l" data-theme="d">D</a></li>
  227. <li><a href="#" data-icon="arrow-r" data-theme="e">E</a></li>
  228. </ul>
  229. </div><!-- /navbar -->
  230. </div><!-- /footer -->
  231. </div><!--/content-primary -->
  232. <div class="content-secondary">
  233. <div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
  234. <h3>More in this section</h3>
  235. <ul data-role="listview" data-theme="c" data-dividertheme="d">
  236. <li data-role="list-divider">Toolbars</li>
  237. <li><a href="docs-bars.html">Toolbar basics</a></li>
  238. <li><a href="docs-headers.html">Header bars</a></li>
  239. <li><a href="docs-footers.html">Footer bars</a></li>
  240. <li data-theme="a"><a href="docs-navbar.html">Navbars</a></li>
  241. <li><a href="bars-fixed.html">Fixed positioning</a></li>
  242. <li><a href="bars-fullscreen.html">Fullscreen positioning</a></li>
  243. <li><a href="footer-persist-a.html">Persistent footer navbar</a></li>
  244. <li><a href="bars-themes.html">Theming toolbars</a></li>
  245. </ul>
  246. </div>
  247. </div>
  248. </div><!-- /content -->
  249. <div data-role="footer" class="footer-docs" data-theme="c">
  250. <p>&copy; 2011-2012 The jQuery Project</p>
  251. </div>
  252. </div><!-- /page -->
  253. </body>
  254. </html>