buttons-icons.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 - Button icons</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>Button icons</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>Adding Icons to Buttons</h2>
  23. <p>The jQuery Mobile framework includes a selected set of icons most often needed for mobile apps. To minimize download size, jQuery Mobile includes a single white icon sprite, and automatically adds a semi-transparent black circle behind the icon to ensure that it has good contrast on any background color.</p>
  24. <p>An icon can be added to a button by adding a <code> data-icon</code> attribute on the anchor specifying the icon to display. For example, the following markup:</p>
  25. <code>
  26. &lt;a href=&quot;index.html&quot; data-role=&quot;button&quot; <strong> data-icon=&quot;delete&quot;</strong>&gt;Delete&lt;/a&gt;
  27. </code>
  28. <p>Creates this button with an icon:</p>
  29. <a href="index.html" data-role="button" data-icon="delete">Delete</a>
  30. <h2>Icon set</h2>
  31. <p>The following <code> data-icon</code> attributes can be referenced to create the icons shown below:</p>
  32. <p><strong>Left arrow</strong> - data-icon="arrow-l"</p>
  33. <a href="index.html" data-role="button" data-icon="arrow-l">My button</a>
  34. <p><strong>Right arrow</strong> - data-icon="arrow-r"</p>
  35. <a href="index.html" data-role="button" data-icon="arrow-r">My button</a>
  36. <p><strong>Up arrow</strong> - data-icon="arrow-u"</p>
  37. <a href="index.html" data-role="button" data-icon="arrow-u">My button</a>
  38. <p><strong>Down arrow</strong> - data-icon="arrow-d"</p>
  39. <a href="index.html" data-role="button" data-icon="arrow-d">My button</a>
  40. <p><strong>Delete</strong> - data-icon="delete"</p>
  41. <a href="index.html" data-role="button" data-icon="delete">My button</a>
  42. <p><strong>Plus</strong> - data-icon="plus"</p>
  43. <a href="index.html" data-role="button" data-icon="plus">My button</a>
  44. <p><strong>Minus</strong> - data-icon="minus"</p>
  45. <a href="index.html" data-role="button" data-icon="minus">My button</a>
  46. <p><strong>Check</strong> - data-icon="check"</p>
  47. <a href="index.html" data-role="button" data-icon="check">My button</a>
  48. <p><strong>Gear</strong> - data-icon="gear"</p>
  49. <a href="index.html" data-role="button" data-icon="gear">My button</a>
  50. <p><strong>Refresh</strong> - data-icon="refresh"</p>
  51. <a href="index.html" data-role="button" data-icon="refresh">My button</a>
  52. <p><strong>Forward</strong> - data-icon="forward"</p>
  53. <a href="index.html" data-role="button" data-icon="forward">My button</a>
  54. <p><strong>Back</strong> - data-icon="back"</p>
  55. <a href="index.html" data-role="button" data-icon="back">My button</a>
  56. <p><strong>Grid</strong> - data-icon="grid"</p>
  57. <a href="index.html" data-role="button" data-icon="grid">My button</a>
  58. <p><strong>Star</strong> - data-icon="star"</p>
  59. <a href="index.html" data-role="button" data-icon="star">My button</a>
  60. <p><strong>Alert</strong> - data-icon="alert"</p>
  61. <a href="index.html" data-role="button" data-icon="alert">My button</a>
  62. <p><strong>Info</strong> - data-icon="info"</p>
  63. <a href="index.html" data-role="button" data-icon="info">My button</a>
  64. <p><strong>Home</strong> - data-icon="home"</p>
  65. <a href="index.html" data-role="button" data-icon="home">My button</a>
  66. <p><strong>Search</strong> - data-icon="search"</p>
  67. <a href="index.html" data-role="button" data-icon="search">My button</a>
  68. <h2>Icon positioning</h2>
  69. <p>By default, all icons in buttons are placed to the left of the button text. </p>
  70. <a href="index.html" data-role="button" data-icon="delete" data-iconpos="left">Delete</a>
  71. <p>This default may be overridden using the <code> data-iconpos</code> attribute to set the icon to the right, above (top) or below (bottom) the text. For example, the markup:</p>
  72. <code>
  73. &lt;a href=&quot;index.html&quot; data-role=&quot;button&quot; data-icon=&quot;delete&quot;<strong> data-iconpos=&quot;right&quot;</strong>&gt;Delete&lt;/a&gt;
  74. </code>
  75. <p>Creates this button with right-aligned icon:</p>
  76. <a href="index.html" data-role="button" data-icon="delete" data-iconpos="right">Delete</a>
  77. <p>Icons can also be positioned above the text by specifying <code> data-iconpos="top"</code></p>
  78. <a href="index.html" data-role="button" data-icon="delete" data-iconpos="top">Delete</a>
  79. <p>Or icons can also be positioned below the text by specifying <code> data-iconpos="bottom"</code></p>
  80. <a href="index.html" data-role="button" data-icon="delete" data-iconpos="bottom">Delete</a>
  81. <p>You can also create an icon-only button, by setting the <code> data-iconpos</code> attribute to <code>notext</code>. The button plugin will hide the text on-screen, but add it as a <code>title</code> attribute on the link to provide context for screen readers and devices that support tooltips. For example, replacing <code> data-iconpos="right"</code> on the previous example with <code> data-iconpos="notext"</code>:</p>
  82. <code>
  83. &lt;a href=&quot;index.html&quot; data-role=&quot;button&quot; data-icon=&quot;delete&quot;<strong> data-iconpos=&quot;notext&quot;</strong>&gt;Delete&lt;/a&gt;
  84. </code>
  85. <p>Creates this icon-only button:</p>
  86. <a href="index.html" data-role="button" data-icon="delete" data-iconpos="notext">Delete</a>
  87. <h2>Custom Icons</h2>
  88. <p>To use custom icons, specify a <code>data-icon</code> value that has a unique name like <code>myapp-email</code> and the button plugin will generate a class by prefixing <code>ui-icon-</code> to the <code> data-icon</code> value and apply it to the button: <code>ui-icon-myapp-email</code>. </p>
  89. <p>You can then write a CSS rule in your stylesheet that targets the <code>ui-icon-myapp-email</code> class to specify the icon background source. To maintain visual consistency with the rest of the icons, create a white icon 18x18 pixels saved as a PNG-8 with alpha transparency.</p>
  90. <p> In this example, we're just pointing to a standalone icon image, but you could just as easily use an icon sprite and specify the positioning instead, just like the icon sprite we use in the framework.</p>
  91. <pre><code>.ui-icon-myapp-email {
  92. background-image: url("app-icon-email.png");
  93. }</code></pre>
  94. <p>This will create the standard resolution icon, but many devices now have very high resolution displays, like the retina display on the iPhone 4. To add a HD icon, create an icon that is 36x36 pixels (exactly double the 18 pixel size), and add second rule that uses the <code>-webkit-min-device-pixel-ratio: 2</code> media query to target a rule only to high resolution displays. Specify the background image for the HD icon file and set the background size to 18x18 pixels which will fit the 36 pixel icon into the same 18 pixel space. The media query block can wrap multiple icon rules:</p>
  95. <pre><code>
  96. @media only screen and (-webkit-min-device-pixel-ratio: 2) {
  97. .ui-icon-myapp-email {
  98. background-image: url("app-icon-email-highres.png");
  99. background-size: 18px 18px;
  100. }
  101. ...more HD icon rules go here...
  102. }
  103. </code></pre>
  104. <h2>Icons and themes</h2>
  105. <p>The semi-transparent black circle behind the white icon ensures good contrast on any background color so it works well with the jQuery Mobile theming system. Here are examples of the same icons sitting on top of a range of different color swatches in out theme.</p>
  106. <!-- A themed -->
  107. <p><strong>Swatch "A"</strong> themed buttons</p>
  108. <div data-role="controlgroup" data-type="horizontal">
  109. <a href="index.html" data-role="button" data-icon="arrow-l" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  110. <a href="index.html" data-role="button" data-icon="arrow-r" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  111. <a href="index.html" data-role="button" data-icon="arrow-u" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  112. <a href="index.html" data-role="button" data-icon="arrow-d" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  113. <a href="index.html" data-role="button" data-icon="delete" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  114. <a href="index.html" data-role="button" data-icon="plus" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  115. <a href="index.html" data-role="button" data-icon="minus" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  116. <a href="index.html" data-role="button" data-icon="check" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  117. <a href="index.html" data-role="button" data-icon="gear" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  118. <a href="index.html" data-role="button" data-icon="refresh" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  119. <a href="index.html" data-role="button" data-icon="forward" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  120. <a href="index.html" data-role="button" data-icon="back" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  121. <a href="index.html" data-role="button" data-icon="grid" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  122. <a href="index.html" data-role="button" data-icon="star" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  123. <a href="index.html" data-role="button" data-icon="alert" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  124. <a href="index.html" data-role="button" data-icon="info" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  125. <a href="index.html" data-role="button" data-icon="home" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  126. <a href="index.html" data-role="button" data-icon="search" data-iconpos="notext" data-theme="a" data-inline="true">My button</a>
  127. </div>
  128. <!-- B themed -->
  129. <p><strong>Swatch "B"</strong> themed buttons</p>
  130. <div data-role="controlgroup" data-type="horizontal">
  131. <a href="index.html" data-role="button" data-icon="arrow-l" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  132. <a href="index.html" data-role="button" data-icon="arrow-r" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  133. <a href="index.html" data-role="button" data-icon="arrow-u" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  134. <a href="index.html" data-role="button" data-icon="arrow-d" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  135. <a href="index.html" data-role="button" data-icon="delete" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  136. <a href="index.html" data-role="button" data-icon="plus" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  137. <a href="index.html" data-role="button" data-icon="minus" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  138. <a href="index.html" data-role="button" data-icon="check" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  139. <a href="index.html" data-role="button" data-icon="gear" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  140. <a href="index.html" data-role="button" data-icon="refresh" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  141. <a href="index.html" data-role="button" data-icon="forward" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  142. <a href="index.html" data-role="button" data-icon="back" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  143. <a href="index.html" data-role="button" data-icon="grid" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  144. <a href="index.html" data-role="button" data-icon="star" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  145. <a href="index.html" data-role="button" data-icon="alert" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  146. <a href="index.html" data-role="button" data-icon="info" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  147. <a href="index.html" data-role="button" data-icon="home" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  148. <a href="index.html" data-role="button" data-icon="search" data-iconpos="notext" data-theme="b" data-inline="true">My button</a>
  149. </div>
  150. <!-- C themed -->
  151. <p><strong>Swatch "C"</strong> themed buttons</p>
  152. <div data-role="controlgroup" data-type="horizontal">
  153. <a href="index.html" data-role="button" data-icon="arrow-l" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  154. <a href="index.html" data-role="button" data-icon="arrow-r" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  155. <a href="index.html" data-role="button" data-icon="arrow-u" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  156. <a href="index.html" data-role="button" data-icon="arrow-d" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  157. <a href="index.html" data-role="button" data-icon="delete" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  158. <a href="index.html" data-role="button" data-icon="plus" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  159. <a href="index.html" data-role="button" data-icon="minus" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  160. <a href="index.html" data-role="button" data-icon="check" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  161. <a href="index.html" data-role="button" data-icon="gear" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  162. <a href="index.html" data-role="button" data-icon="refresh" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  163. <a href="index.html" data-role="button" data-icon="forward" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  164. <a href="index.html" data-role="button" data-icon="back" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  165. <a href="index.html" data-role="button" data-icon="grid" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  166. <a href="index.html" data-role="button" data-icon="star" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  167. <a href="index.html" data-role="button" data-icon="alert" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  168. <a href="index.html" data-role="button" data-icon="info" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  169. <a href="index.html" data-role="button" data-icon="home" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  170. <a href="index.html" data-role="button" data-icon="search" data-iconpos="notext" data-theme="c" data-inline="true">My button</a>
  171. </div>
  172. </div><!--/content-primary -->
  173. <div class="content-secondary">
  174. <div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
  175. <h3>More in this section</h3>
  176. <ul data-role="listview" data-theme="c" data-dividertheme="d">
  177. <li data-role="list-divider">Buttons</li>
  178. <li><a href="buttons-types.html">Button basics</a></li>
  179. <li data-theme="a"><a href="buttons-icons.html">Button icons</a></li>
  180. <li><a href="buttons-inline.html">Inline buttons</a></li>
  181. <li><a href="buttons-grouped.html">Grouped buttons</a></li>
  182. <li><a href="buttons-themes.html">Theming buttons</a></li>
  183. </ul>
  184. </div>
  185. </div>
  186. </div><!-- /content -->
  187. <div data-role="footer" class="footer-docs" data-theme="c">
  188. <p>&copy; 2011-2012 The jQuery Project</p>
  189. </div>
  190. </div><!-- /page -->
  191. </body>
  192. </html>