mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-04-05 15:10:59 +00:00
Re-vamped the navbar docs to fix incorrect info about icon positioning and theming. Fixes #1858, Fixes #1797, Fixes #2667, Fixes #1180, Fixes #2373
The docs incorrectly stated that the icon position could be set per link, but this is intended as a global setting for the navbar parent. This is working as designed and helps with visual consistency. If icon positioning needs to be be adjusted per link, you will need to manually apply the right classes through JS and may need to tweak CSS because top/bottom and left/right positions have different heights.
This commit is contained in:
parent
e4834a8db7
commit
15e984eca6
1 changed files with 108 additions and 34 deletions
|
|
@ -24,35 +24,32 @@
|
|||
<div class="content-primary">
|
||||
<h2>Simple navbar</h2>
|
||||
|
||||
<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. </p>
|
||||
|
||||
<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 nav bar</a> variation that works more like a tab bar that stays fixed as you navigate across pages.</p>
|
||||
<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>
|
||||
|
||||
<pre><code>
|
||||
<div data-role="footer">
|
||||
<div data-role="navbar">
|
||||
<ul>
|
||||
<li><a href="a.html" class="ui-btn-active">One</a></li>
|
||||
<li><a href="b.html">Two</a></li>
|
||||
</ul>
|
||||
</div><!-- /navbar -->
|
||||
</div><!-- /footer -->
|
||||
<strong><div data-role="navbar"></strong>
|
||||
<ul>
|
||||
<li><a href="a.html" class="ui-btn-active">One</a></li>
|
||||
<li><a href="b.html">Two</a></li>
|
||||
</ul>
|
||||
<strong></div><!-- /navbar --></strong>
|
||||
</code></pre>
|
||||
|
||||
<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>
|
||||
|
||||
<div data-role="footer">
|
||||
|
||||
<div data-role="navbar">
|
||||
<ul>
|
||||
<li><a href="#" class="ui-btn-active">One</a></li>
|
||||
<li><a href="#">Two</a></li>
|
||||
</ul>
|
||||
</div><!-- /navbar -->
|
||||
</div><!-- /footer -->
|
||||
|
||||
|
||||
<p>Adding a third item will automatically make each button 1/3 the width of the browser window:</p>
|
||||
|
||||
<div data-role="footer">
|
||||
|
||||
<div data-role="navbar">
|
||||
<ul>
|
||||
<li><a href="#" class="ui-btn-active">One</a></li>
|
||||
|
|
@ -60,11 +57,11 @@
|
|||
<li><a href="#">Three</a></li>
|
||||
</ul>
|
||||
</div><!-- /navbar -->
|
||||
</div><!-- /footer -->
|
||||
|
||||
|
||||
<p>Adding a fourth more item will automatically make each button 1/4 the width of the browser window:</p>
|
||||
|
||||
<div data-role="footer">
|
||||
|
||||
<div data-role="navbar" data-grid="c">
|
||||
<ul>
|
||||
<li><a href="#" class="ui-btn-active">One</a></li>
|
||||
|
|
@ -73,11 +70,11 @@
|
|||
<li><a href="#">Four</a></li>
|
||||
</ul>
|
||||
</div><!-- /navbar -->
|
||||
</div><!-- /footer -->
|
||||
|
||||
|
||||
<p>The navbar maxes out with 5 items, each 1/5 the width of the browser window:</p>
|
||||
|
||||
<div data-role="footer">
|
||||
|
||||
<div data-role="navbar" data-grid="d">
|
||||
<ul>
|
||||
<li><a href="#" class="ui-btn-active">One</a></li>
|
||||
|
|
@ -87,11 +84,10 @@
|
|||
<li><a href="#">Five</a></li>
|
||||
</ul>
|
||||
</div><!-- /navbar -->
|
||||
</div><!-- /footer -->
|
||||
|
||||
|
||||
<p>If more than 5 items are added, the navbar will simply wrap to multiple lines:</p>
|
||||
|
||||
<div data-role="footer">
|
||||
<div data-role="navbar">
|
||||
<ul>
|
||||
<li><a href="#" class="ui-btn-active">One</a></li>
|
||||
|
|
@ -106,17 +102,14 @@
|
|||
<li><a href="#">Ten</a></li>
|
||||
</ul>
|
||||
</div><!-- /navbar -->
|
||||
</div><!-- /footer -->
|
||||
|
||||
<p>As a fallback, navbars with 1 item will simply render as 100%.</p>
|
||||
|
||||
<div data-role="footer">
|
||||
<div data-role="navbar">
|
||||
<ul>
|
||||
<li><a href="#" class="ui-btn-active">One</a></li>
|
||||
</ul>
|
||||
</div><!-- /navbar -->
|
||||
</div><!-- /footer -->
|
||||
|
||||
<h2>Navbars in headers</h2>
|
||||
|
||||
|
|
@ -135,9 +128,33 @@
|
|||
</div><!-- /navbar -->
|
||||
</div><!-- /header -->
|
||||
|
||||
<h2>Navbars in footers</h2>
|
||||
|
||||
<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>
|
||||
<pre><code>
|
||||
<div data-role="footer">
|
||||
<div data-role="navbar">
|
||||
<ul>
|
||||
<li><a href="#">One</a></li>
|
||||
<li><a href="#">Two</a></li>
|
||||
<li><a href="#">Three</a></li>
|
||||
</ul>
|
||||
</div><!-- /navbar -->
|
||||
</div><!-- /footer -->
|
||||
</code></pre>
|
||||
<div data-role="footer">
|
||||
<div data-role="navbar">
|
||||
<ul>
|
||||
<li><a href="#">One</a></li>
|
||||
<li><a href="#">Two</a></li>
|
||||
<li><a href="#">Three</a></li>
|
||||
</ul>
|
||||
</div><!-- /navbar -->
|
||||
</div><!-- /footer -->
|
||||
|
||||
<h2>Icons in navbars</h2>
|
||||
|
||||
<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.</p>
|
||||
<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>
|
||||
|
||||
<div data-role="footer">
|
||||
<div data-role="navbar">
|
||||
|
|
@ -149,14 +166,41 @@
|
|||
</div><!-- /navbar -->
|
||||
</div><!-- /footer -->
|
||||
|
||||
<p>Icons can be stacked above the labels by adding the <code> data-iconpos="top"</code> attribute to each anchor.</p>
|
||||
<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 navbar container.</p>
|
||||
<pre><code>
|
||||
<div data-role="navbar" <strong>data-iconpos="bottom"</strong>>
|
||||
</code></pre>
|
||||
<p>This will result in a bottom icon alignment:</p>
|
||||
<div data-role="footer">
|
||||
<div data-role="navbar" data-iconpos="bottom">
|
||||
<ul>
|
||||
<li><a href="#" data-icon="grid">Summary</a></li>
|
||||
<li><a href="#" data-icon="star" class="ui-btn-active">Favs</a></li>
|
||||
<li><a href="#" data-icon="gear">Setup</a></li>
|
||||
</ul>
|
||||
</div><!-- /navbar -->
|
||||
</div><!-- /footer -->
|
||||
|
||||
<p>The icon position can be set to <code>data-iconpos="left"</code>:</p>
|
||||
|
||||
<div data-role="footer">
|
||||
<div data-role="navbar">
|
||||
<div data-role="navbar" data-iconpos="left">
|
||||
<ul>
|
||||
<li><a href="#" data-icon="grid" data-iconpos="top">Summary</a></li>
|
||||
<li><a href="#" data-icon="star" class="ui-btn-active" data-iconpos="top">Favs</a></li>
|
||||
<li><a href="#" data-icon="gear" data-iconpos="top">Setup</a></li>
|
||||
<li><a href="#" data-icon="grid">Summary</a></li>
|
||||
<li><a href="#" data-icon="star" class="ui-btn-active">Favs</a></li>
|
||||
<li><a href="#" data-icon="gear">Setup</a></li>
|
||||
</ul>
|
||||
</div><!-- /navbar -->
|
||||
</div><!-- /footer -->
|
||||
|
||||
<p>Or the icon position can be set to <code>data-iconpos="right"</code>:</p>
|
||||
|
||||
<div data-role="footer">
|
||||
<div data-role="navbar" data-iconpos="right">
|
||||
<ul>
|
||||
<li><a href="#" data-icon="grid">Summary</a></li>
|
||||
<li><a href="#" data-icon="star" class="ui-btn-active">Favs</a></li>
|
||||
<li><a href="#" data-icon="gear">Setup</a></li>
|
||||
</ul>
|
||||
</div><!-- /navbar -->
|
||||
</div><!-- /footer -->
|
||||
|
|
@ -194,14 +238,44 @@
|
|||
|
||||
<h2>Theming navbars</h2>
|
||||
|
||||
<p>Navbars can be set to any theme color by <code> data-theme</code> attribute to the links and specifying any theme swatch.</p>
|
||||
<p>Navbars inherit the theme swatch from their parent container, just like buttons. If a navbar is placed in header or footer toolbar, it will inherit the default toolbar swatch (A) for bars unless you set this in the markup. </p>
|
||||
<p>Here are a few examples of navbars in various container swatches 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>
|
||||
|
||||
<div data-role="footer">
|
||||
<div data-role="navbar" data-theme="e" >
|
||||
<div class="ui-body-a ui-body">
|
||||
<h3>Swatch A</h3>
|
||||
<div data-role="navbar">
|
||||
<ul>
|
||||
<li><a href="#" data-icon="grid" data-iconpos="top" data-theme="b">Summary</a></li>
|
||||
<li><a href="#" data-icon="star" class="ui-btn-active" data-iconpos="top" data-theme="b">Favs</a></li>
|
||||
<li><a href="#" data-icon="gear" data-iconpos="top" data-theme="b">Setup</a></li>
|
||||
<li><a href="#" data-icon="grid">A</a></li>
|
||||
<li><a href="#" data-icon="star">B</a></li>
|
||||
<li><a href="#" data-icon="gear">C</a></li>
|
||||
<li><a href="#" data-icon="arrow-l">D</a></li>
|
||||
<li><a href="#" data-icon="arrow-r">E</a></li>
|
||||
</ul>
|
||||
</div><!-- /navbar -->
|
||||
</div><!-- /container -->
|
||||
|
||||
<div class="ui-body-d ui-body">
|
||||
<h3>Swatch B</h3>
|
||||
<div data-role="navbar">
|
||||
<ul>
|
||||
<li><a href="#" data-icon="grid">A</a></li>
|
||||
<li><a href="#" data-icon="star">B</a></li>
|
||||
<li><a href="#" data-icon="gear">C</a></li>
|
||||
<li><a href="#" data-icon="arrow-l">D</a></li>
|
||||
<li><a href="#" data-icon="arrow-r">E</a></li>
|
||||
</ul>
|
||||
</div><!-- /navbar -->
|
||||
</div><!-- /container -->
|
||||
|
||||
<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 at the navbar container is <em>not</em> supported.</p>
|
||||
<div data-role="footer">
|
||||
<div data-role="navbar">
|
||||
<ul>
|
||||
<li><a href="#" data-icon="grid"data-theme="a">A</a></li>
|
||||
<li><a href="#" data-icon="star" data-theme="b">B</a></li>
|
||||
<li><a href="#" data-icon="gear" data-theme="c">C</a></li>
|
||||
<li><a href="#" data-icon="arrow-l" data-theme="d">D</a></li>
|
||||
<li><a href="#" data-icon="arrow-r" data-theme="e">E</a></li>
|
||||
</ul>
|
||||
</div><!-- /navbar -->
|
||||
</div><!-- /footer -->
|
||||
|
|
|
|||
Loading…
Reference in a new issue