8091ac6ad7da50f24b88a9cff17b3acf3303ffc3
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / docs / toolbars / docs-navbar.html
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="../../css/themes/default/" />  
8         <link rel="stylesheet" href="../_assets/css/jqm-docs.css"/>
9         <script src="../../js/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="../../js/"></script>
13 </head> 
14 <body> 
15
16         <div data-role="page" class="type-interior">
17
18                 <div data-role="header" data-theme="f">
19                 <h1>Navbar</h1>
20                 <a href="../../" data-icon="home" data-iconpos="notext" data-direction="reverse" class="ui-btn-right jqm-home">Home</a>
21         </div><!-- /header -->
22
23         <div data-role="content">
24                 <div class="content-primary">           
25         <h2>Simple navbar</h2>
26         
27         <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>
28         <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>
29         
30 <pre><code>
31 <strong>&lt;div data-role=&quot;navbar&quot;&gt;</strong>
32         &lt;ul&gt;
33                 &lt;li&gt;&lt;a href=&quot;a.html&quot; class=&quot;ui-btn-active&quot;&gt;One&lt;/a&gt;&lt;/li&gt;
34                 &lt;li&gt;&lt;a href=&quot;b.html&quot;&gt;Two&lt;/a&gt;&lt;/li&gt;
35         &lt;/ul&gt;
36 <strong>&lt;/div&gt;&lt;!-- /navbar --&gt;</strong>
37 </code></pre>
38
39         <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>
40
41
42                 <div data-role="navbar">
43                         <ul>
44                                 <li><a href="#" class="ui-btn-active">One</a></li>
45                                 <li><a href="#">Two</a></li>
46                         </ul>
47                 </div><!-- /navbar -->
48
49         
50         <p>Adding a third item will automatically make each button 1/3 the width of the browser window:</p>
51
52
53                 <div data-role="navbar">
54                         <ul>
55                                 <li><a href="#" class="ui-btn-active">One</a></li>
56                                 <li><a href="#">Two</a></li>
57                                 <li><a href="#">Three</a></li>
58                         </ul>
59                 </div><!-- /navbar -->
60
61         
62         <p>Adding a fourth more item will automatically make each button 1/4 the width of the browser window:</p>
63
64
65                 <div data-role="navbar" data-grid="c">
66                         <ul>
67                                 <li><a href="#" class="ui-btn-active">One</a></li>
68                                 <li><a href="#">Two</a></li>
69                                 <li><a href="#">Three</a></li>
70                                 <li><a href="#">Four</a></li>
71                         </ul>
72                 </div><!-- /navbar -->
73
74
75         <p>The navbar maxes out with 5 items, each 1/5 the width of the browser window:</p>
76
77
78                 <div data-role="navbar" data-grid="d">
79                         <ul>
80                                 <li><a href="#" class="ui-btn-active">One</a></li>
81                                 <li><a href="#">Two</a></li>
82                                 <li><a href="#">Three</a></li>
83                                 <li><a href="#">Four</a></li>
84                                 <li><a href="#">Five</a></li>
85                         </ul>
86                 </div><!-- /navbar -->
87
88         
89         <p>If more than 5 items are added, the navbar will simply wrap to multiple lines:</p>
90         
91                 <div data-role="navbar">
92                         <ul>
93                                 <li><a href="#" class="ui-btn-active">One</a></li>
94                                 <li><a href="#">Two</a></li>
95                                 <li><a href="#">Three</a></li>
96                                 <li><a href="#">Four</a></li>
97                                 <li><a href="#">Five</a></li>
98                                 <li><a href="#">Six</a></li>
99                                 <li><a href="#">Seven</a></li>
100                                 <li><a href="#">Eight</a></li>
101                                 <li><a href="#">Nine</a></li>
102                                 <li><a href="#">Ten</a></li>
103                         </ul>
104                 </div><!-- /navbar -->
105         
106         <p>As a fallback, navbars with 1 item will simply render as 100%.</p>
107         
108                 <div data-role="navbar">
109                         <ul>
110                                 <li><a href="#" class="ui-btn-active">One</a></li>
111                         </ul>
112                 </div><!-- /navbar -->
113         
114         <h2>Navbars in headers</h2>
115         
116         <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>
117
118         <div data-role="header">
119                 <h1>I'm a header</h1>
120                 <a href="index.html" data-icon="gear" class="ui-btn-right">Options</a>
121                                 
122                 <div data-role="navbar">
123                         <ul>
124                                 <li><a href="#">One</a></li>
125                                 <li><a href="#">Two</a></li>
126                                 <li><a href="#">Three</a></li>
127                         </ul>
128                 </div><!-- /navbar -->
129         </div><!-- /header -->
130         
131         <h2>Navbars in footers</h2>
132         
133         <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>
134 <pre><code>
135 &lt;div data-role=&quot;footer&quot;&gt;                
136         &lt;div data-role=&quot;navbar&quot;&gt;
137                 &lt;ul&gt;
138                         &lt;li&gt;&lt;a href=&quot;#&quot;&gt;One&lt;/a&gt;&lt;/li&gt;
139                         &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Two&lt;/a&gt;&lt;/li&gt;
140                         &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Three&lt;/a&gt;&lt;/li&gt;
141                 &lt;/ul&gt;
142         &lt;/div&gt;&lt;!-- /navbar --&gt;
143 &lt;/div&gt;&lt;!-- /footer --&gt;
144 </code></pre>
145         <div data-role="footer">                
146                 <div data-role="navbar">
147                         <ul>
148                                 <li><a href="#">One</a></li>
149                                 <li><a href="#">Two</a></li>
150                                 <li><a href="#">Three</a></li>
151                         </ul>
152                 </div><!-- /navbar -->
153         </div><!-- /footer -->
154         
155         <h2>Icons in navbars</h2>
156         
157         <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>
158
159         <div data-role="footer">
160                 <div data-role="navbar">
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         
169         <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>
170 <pre><code>
171 &lt;div data-role=&quot;navbar&quot; <strong>data-iconpos=&quot;bottom&quot;</strong>&gt;
172 </code></pre>
173         <p>This will result in a bottom icon alignment:</p>
174         <div data-role="footer">
175                 <div data-role="navbar" data-iconpos="bottom">
176                         <ul>
177                                 <li><a href="#" data-icon="grid">Summary</a></li>
178                                 <li><a href="#" data-icon="star" class="ui-btn-active">Favs</a></li>
179                                 <li><a href="#" data-icon="gear">Setup</a></li>
180                         </ul>
181                 </div><!-- /navbar -->
182         </div><!-- /footer -->
183         
184         <p>The icon position can be set to <code>data-iconpos="left"</code>:</p>
185
186         <div data-role="footer">
187                 <div data-role="navbar" data-iconpos="left">
188                         <ul>
189                                 <li><a href="#" data-icon="grid">Summary</a></li>
190                                 <li><a href="#" data-icon="star" class="ui-btn-active">Favs</a></li>
191                                 <li><a href="#" data-icon="gear">Setup</a></li>
192                         </ul>
193                 </div><!-- /navbar -->
194         </div><!-- /footer -->
195         
196         <p>Or the icon position can be set to <code>data-iconpos="right"</code>:</p>
197
198         <div data-role="footer">
199                 <div data-role="navbar" data-iconpos="right">
200                         <ul>
201                                 <li><a href="#" data-icon="grid">Summary</a></li>
202                                 <li><a href="#" data-icon="star" class="ui-btn-active">Favs</a></li>
203                                 <li><a href="#" data-icon="gear">Setup</a></li>
204                         </ul>
205                 </div><!-- /navbar -->
206         </div><!-- /footer -->
207         
208         <h2>Using 3rd party icon sets</h2>
209         
210         <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>
211         
212         
213         <style> 
214                 .nav-glyphish-example .ui-btn .ui-btn-inner { padding-top: 40px !important; }
215                 .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; }
216                 #chat .ui-icon { background:  url(glyphish-icons/09-chat2.png) 50% 50% no-repeat; background-size: 24px 22px; }
217                 #email .ui-icon { background:  url(glyphish-icons/18-envelope.png) 50% 50% no-repeat; background-size: 24px 16px;  }
218                 #login .ui-icon { background:  url(glyphish-icons/30-key.png) 50% 50% no-repeat;  background-size: 12px 26px; }
219                 #beer .ui-icon { background:  url(glyphish-icons/88-beermug.png) 50% 50% no-repeat;  background-size: 22px 27px; }
220                 #coffee .ui-icon { background:  url(glyphish-icons/100-coffee.png) 50% 50% no-repeat;  background-size: 20px 24px; }
221                 #skull .ui-icon { background:  url(glyphish-icons/21-skull.png) 50% 50% no-repeat;  background-size: 22px 24px; }
222         </style>
223         
224         <div data-role="footer" class="nav-glyphish-example">
225                 <div data-role="navbar" class="nav-glyphish-example" data-grid="d">
226                 <ul>
227                         <li><a href="#" id="chat" data-icon="custom">Chat</a></li>
228                         <li><a href="#" id="email" data-icon="custom">Email</a></li>
229                         <li><a href="#" id="skull" data-icon="custom">Danger</a></li>
230                         <li><a href="#" id="beer" data-icon="custom">Beer</a></li>
231                         <li><a href="#" id="coffee" data-icon="custom">Coffee</a></li>
232                 </ul>
233                 </div>
234         </div>
235         
236         <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>
237
238
239         <h2>Theming navbars</h2>
240         
241         <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>
242         <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>
243
244         <div class="ui-body-a ui-body">
245                 <h3>Swatch A</h3>
246                 <div data-role="navbar">
247                         <ul>
248                                 <li><a href="#" data-icon="grid">A</a></li>
249                                 <li><a href="#" data-icon="star">B</a></li>
250                                 <li><a href="#" data-icon="gear">C</a></li>
251                                 <li><a href="#" data-icon="arrow-l">D</a></li>
252                                 <li><a href="#" data-icon="arrow-r">E</a></li>
253                         </ul>
254                 </div><!-- /navbar -->
255         </div><!-- /container -->
256         
257         <div class="ui-body-d ui-body">
258                 <h3>Swatch B</h3>
259                 <div data-role="navbar">
260                         <ul>
261                                 <li><a href="#" data-icon="grid">A</a></li>
262                                 <li><a href="#" data-icon="star">B</a></li>
263                                 <li><a href="#" data-icon="gear">C</a></li>
264                                 <li><a href="#" data-icon="arrow-l">D</a></li>
265                                 <li><a href="#" data-icon="arrow-r">E</a></li>
266                         </ul>
267                 </div><!-- /navbar -->
268         </div><!-- /container -->
269         
270 <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>
271         <div data-role="footer">
272                 <div data-role="navbar">
273                         <ul>
274                                 <li><a href="#" data-icon="grid"data-theme="a">A</a></li>
275                                 <li><a href="#" data-icon="star" data-theme="b">B</a></li>
276                                 <li><a href="#" data-icon="gear" data-theme="c">C</a></li>
277                                 <li><a href="#" data-icon="arrow-l" data-theme="d">D</a></li>
278                                 <li><a href="#" data-icon="arrow-r" data-theme="e">E</a></li>
279                         </ul>
280                 </div><!-- /navbar -->
281         </div><!-- /footer -->
282                                         
283
284                 </div><!--/content-primary -->          
285
286                 <div class="content-secondary">
287
288                         <div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
289
290                                         <h3>More in this section</h3>
291
292                                         <ul data-role="listview" data-theme="c" data-dividertheme="d">
293
294                                                 <li data-role="list-divider">Toolbars</li>
295                                                 <li><a href="docs-bars.html">Toolbar basics</a></li>
296                                                 <li><a href="docs-headers.html">Header bars</a></li>
297                                                 <li><a href="docs-footers.html">Footer bars</a></li>
298                                                 <li data-theme="a"><a href="docs-navbar.html">Navbars</a></li>
299                                                 <li><a href="bars-fixed.html">Fixed positioning</a></li>
300                                                 <li><a href="bars-fullscreen.html">Fullscreen positioning</a></li>
301                                                 <li><a href="footer-persist-a.html">Persistent footer navbar</a></li>
302                                                 <li><a href="bars-themes.html">Theming toolbars</a></li>
303
304                                         </ul>
305                         </div>
306                 </div>          
307
308         </div><!-- /content -->
309
310         <div data-role="footer" class="footer-docs" data-theme="c">
311                         <p>&copy; 2011 The jQuery Project</p>
312         </div>
313
314         </div><!-- /page -->
315
316         </body>
317         </html>