content-grids.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 - Content Grids</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>Layout grids</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. <p>Using multiple column layouts isn't generally recommended on a mobile device because of the narrow screen width, but there are times where you may need to place small elements side-by-side (like buttons or navigation tabs, for example). </p>
  23. <p>The jQuery Mobile framework provides a simple way to build CSS-based columns through a block style class convention called <code>ui-grid</code>. </p>
  24. <p>There are four preset configurations layouts that can be used in any situation that requires columns:</p>
  25. <ul>
  26. <li><strong>two</strong>-column (using the <code>ui-grid-a</code> class)</li>
  27. <li><strong>three</strong>-column (using the <code>ui-grid-b</code> class)</li>
  28. <li><strong>four</strong>-column (using the <code>ui-grid-c</code> class)</li>
  29. <li><strong>five</strong>-column (using the <code>ui-grid-d</code> class)</li>
  30. </ul>
  31. <p>Grids are 100% width, completely invisible (no borders or backgrounds) and don't have padding or margins, so they shouldn't interfere with the styles of elements placed inside them. </p>
  32. <p>Within the grid container, child elements are assigned <code>ui-block-a/b/c/d</code> in a sequential manner which makes each "block" element float side-by-side, forming the grid. The <code>ui-block-a</code> class essentially clears the floats which will start a new line (see multiple row grids, below).</p>
  33. <h2>Two column grids</h2>
  34. <p>To build a two-column (50/50%) layout, start with a container with a <code>class</code> of <code>ui-grid-a</code>, and add two child containers inside it classed with <code>ui-block-a</code> for the first column and <code>ui-block-b</code> for the second:</p>
  35. <pre><code>
  36. &lt;div class=&quot;ui-grid-a&quot;&gt;
  37. &lt;div class=&quot;ui-block-a&quot;&gt;&lt;strong&gt;I'm Block A&lt;/strong&gt; and text inside will wrap&lt;/div&gt;
  38. &lt;div class=&quot;ui-block-b&quot;&gt;&lt;strong&gt;I'm Block B&lt;/strong&gt; and text inside will wrap&lt;/div&gt;
  39. &lt;/div&gt;&lt;!-- /grid-a --&gt;
  40. </code></pre>
  41. <p>The above markup produces the following content layout:</p>
  42. <div class="ui-grid-a">
  43. <div class="ui-block-a"><strong>I'm Block A</strong> and text inside will wrap.</div>
  44. <div class="ui-block-b"><strong>I'm Block B</strong> and text inside will wrap.</div>
  45. </div><!-- /grid-a -->
  46. <p>As you see above, by default grid blocks have no visual styling; they simply present content side-by-side.</p>
  47. <p>Grid classes can be applied to any container. In this next example, we add <code>ui-grid-a</code> to a <code>fieldset</code>, and apply the <code>ui-block</code> classes to the two buttons inside to stretch them each to 50% of the screen width:</p>
  48. <pre><code>
  49. &lt;fieldset class=&quot;ui-grid-a&quot;&gt;
  50. &lt;div class=&quot;ui-block-a&quot;&gt;&lt;button type=&quot;submit&quot; data-theme=&quot;c&quot;&gt;Cancel&lt;/button&gt;&lt;/div&gt;
  51. &lt;div class=&quot;ui-block-b&quot;&gt;&lt;button type=&quot;submit&quot; data-theme=&quot;b&quot;&gt;Submit&lt;/button&gt;&lt;/div&gt;
  52. &lt;/fieldset&gt;
  53. </code></pre>
  54. <fieldset class="ui-grid-a">
  55. <div class="ui-block-a"><button type="submit" data-theme="c">Cancel</button></div>
  56. <div class="ui-block-b"><button type="submit" data-theme="b">Submit</button></div>
  57. </fieldset>
  58. <p>Theme classes (not data-theme attributes) from the <a href="../api/themes.html">theming system</a> can be added to an element, including grids. On the blocks below, we're adding two classes: <code>ui-bar</code> to add the default bar padding and <code>ui-bar-e</code> to apply the background gradient and font styling for the "e" toolbar theme swatch. For illustration purposes, an inline <code>style="height:120px"</code> attribute is also added to each grid to set each to a standard height. </p>
  59. <div class="ui-grid-a">
  60. <div class="ui-block-a"><div class="ui-bar ui-bar-e" style="height:120px">Block A</div></div>
  61. <div class="ui-block-b"><div class="ui-bar ui-bar-e" style="height:120px">Block B</div></div>
  62. </div><!-- /grid-a -->
  63. <h2>Three-column grids</h2>
  64. <p>The other grid layout configuration uses <code>class=ui-grid-b</code> on the parent, and 3 child container elements, each with its respective <code>ui-block-a/b/c</code> class, to create a three-column layout (33/33/33%). Note: These blocks are also styled with theme classes so the grid layout is clearly visible.</p>
  65. <pre><code>
  66. &lt;div class=&quot;ui-grid-b&quot;&gt;
  67. &lt;div class=&quot;ui-block-a&quot;&gt;Block A&lt;/div&gt;
  68. &lt;div class=&quot;ui-block-b&quot;&gt;Block B&lt;/div&gt;
  69. &lt;div class=&quot;ui-block-c&quot;&gt;Block C&lt;/div&gt;
  70. &lt;/div&gt;&lt;!-- /grid-b --&gt;
  71. </code></pre>
  72. <p>This will produce a 33/33/33% grid for our content.</p>
  73. <div class="ui-grid-b">
  74. <div class="ui-block-a"><div class="ui-bar ui-bar-e" style="height:120px">Block A</div></div>
  75. <div class="ui-block-b"><div class="ui-bar ui-bar-e" style="height:120px">Block B</div></div>
  76. <div class="ui-block-c"><div class="ui-bar ui-bar-e" style="height:120px">Block C</div></div>
  77. </div><!-- /grid-b -->
  78. <p>And an example of a 3 column grid with buttons inside:</p>
  79. <fieldset class="ui-grid-b">
  80. <div class="ui-block-a"><button type="submit" data-theme="c">Hmm</button></div>
  81. <div class="ui-block-b"><button type="submit" data-theme="a">No</button></div>
  82. <div class="ui-block-b"><button type="submit" data-theme="b">Yes</button></div>
  83. </fieldset>
  84. <h2>Four-column grids</h2>
  85. <p>A four-column, 25/25/25/25% grid is created by specifying <code>class=ui-grid-c</code> on the parent and adding a fourth block. Note: These blocks are also styled with theme classes so the grid layout is clearly visible.</p>
  86. <div class="ui-grid-c">
  87. <div class="ui-block-a"><div class="ui-bar ui-bar-e" style="height:120px">A</div></div>
  88. <div class="ui-block-b"><div class="ui-bar ui-bar-e" style="height:120px">B</div></div>
  89. <div class="ui-block-c"><div class="ui-bar ui-bar-e" style="height:120px">C</div></div>
  90. <div class="ui-block-d"><div class="ui-bar ui-bar-e" style="height:120px">D</div></div>
  91. </div><!-- /grid-c -->
  92. <h2>Five-column grids</h2>
  93. <p>A five-column, 20/20/20/20/20% grid is created by specifying <code>class=ui-grid-d</code> on the parent and adding a fourth block. Note: These blocks are also styled with theme classes so the grid layout is clearly visible.</p>
  94. <div class="ui-grid-d">
  95. <div class="ui-block-a"><div class="ui-bar ui-bar-e" style="height:120px">A</div></div>
  96. <div class="ui-block-b"><div class="ui-bar ui-bar-e" style="height:120px">B</div></div>
  97. <div class="ui-block-c"><div class="ui-bar ui-bar-e" style="height:120px">C</div></div>
  98. <div class="ui-block-d"><div class="ui-bar ui-bar-e" style="height:120px">D</div></div>
  99. <div class="ui-block-e"><div class="ui-bar ui-bar-e" style="height:120px">E</div></div>
  100. </div><!-- /grid-c -->
  101. <h2>Multiple row grids</h2>
  102. <p>Grids are designed to wrap to multiple rows of items. For example, if you specify a 3-column grid (ui-grid-b) on a container that has nine child blocks, it will wrap to 3 rows of 3 items each. There is a CSS rule to clear the floats and start a new line when the <code>class=ui-block-a</code> is seen so make sure to assign block classes in a repeating sequence (a, b, c, a, b, c, etc.) that maps to the grid type:</p>
  103. <div class="ui-grid-b">
  104. <div class="ui-block-a"><div class="ui-bar ui-bar-e" style="height:120px">A</div></div>
  105. <div class="ui-block-b"><div class="ui-bar ui-bar-e" style="height:120px">B</div></div>
  106. <div class="ui-block-c"><div class="ui-bar ui-bar-e" style="height:120px">C</div></div>
  107. <div class="ui-block-a"><div class="ui-bar ui-bar-e" style="height:120px">A</div></div>
  108. <div class="ui-block-b"><div class="ui-bar ui-bar-e" style="height:120px">B</div></div>
  109. <div class="ui-block-c"><div class="ui-bar ui-bar-e" style="height:120px">C</div></div>
  110. <div class="ui-block-a"><div class="ui-bar ui-bar-e" style="height:120px">A</div></div>
  111. <div class="ui-block-b"><div class="ui-bar ui-bar-e" style="height:120px">B</div></div>
  112. <div class="ui-block-c"><div class="ui-bar ui-bar-e" style="height:120px">C</div></div>
  113. </div><!-- /grid-c -->
  114. <h2>Grids in toolbars</h2>
  115. <p>Grids are helpful for creating layouts within a toolbar. Here's a footer with a 3 column grid.</p>
  116. <!-- NOTE: Inline styles are for demo purposes only, please use external styles -->
  117. <div data-role="footer" data-theme="a" class="ui-bar ui-grid-c">
  118. <div class="ui-block-a"><h3 style="margin-top:10px;">Settings</h3></div>
  119. <div class="ui-block-b"><label for="value" style="margin:8px 10px 0 0; text-align:right;">Price</label> </div>
  120. <div class="ui-block-c"><input id="value" value="5,000"></div>
  121. <div class="ui-block-d"><div style="margin:6px 0 0 10px;"><button type="submit" data-theme="b">Update</button></div></div>
  122. </div><!-- /footer -->
  123. </div><!--/content-primary -->
  124. <div class="content-secondary">
  125. <div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
  126. <h3>More in this section</h3>
  127. <ul data-role="listview" data-theme="c" data-dividertheme="d">
  128. <li data-role="list-divider">Content Formatting</li>
  129. <li><a href="content-html.html">Basic HTML styles</a></li>
  130. <li data-theme="a"><a href="content-grids.html">Layout grids (columns)</a></li>
  131. <li><a href="content-collapsible.html">Collapsible content blocks</a></li>
  132. <li><a href="content-collapsible-set.html">Collapsible sets (accordions)</a></li>
  133. <li><a href="content-themes.html">Theming content</a></li>
  134. </ul>
  135. </div>
  136. </div>
  137. </div><!-- /content -->
  138. <div data-role="footer" class="footer-docs" data-theme="c">
  139. <p>&copy; 2011-2012 The jQuery Project</p>
  140. </div>
  141. </div><!-- /page -->
  142. </body>
  143. </html>