|
| 1 | +<?xml version="1.0"?> |
| 2 | +<?xml-stylesheet type="text/xsl" href="../entries2html.xsl" ?> |
| 3 | +<entry name="grid-layout" namespace="fn" type="misc" widgetnamespace="mobile"> |
| 4 | + <title>Grid Layout</title> |
| 5 | + <desc>Multi-column layout grids</desc> |
| 6 | + <longdesc> |
| 7 | + <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> |
| 8 | + <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> |
| 9 | + <p>There are four preset layouts that can be used in any situation that requires columns:</p> |
| 10 | + <ul> |
| 11 | + <li><strong>two</strong>-column (using the <code>ui-grid-a</code> class)</li> |
| 12 | + <li><strong>three</strong>-column (using the <code>ui-grid-b</code> class)</li> |
| 13 | + <li><strong>four</strong>-column (using the <code>ui-grid-c</code> class)</li> |
| 14 | + <li><strong>five</strong>-column (using the <code>ui-grid-d</code> class)</li> |
| 15 | + </ul> |
| 16 | + <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> |
| 17 | + <p>Within the grid container, child elements are assigned <code>ui-block-a/b/c/d/e</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> |
| 18 | + |
| 19 | + <h2>Two column grids</h2> |
| 20 | + |
| 21 | + <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> |
| 22 | + |
| 23 | +<pre><code> |
| 24 | +<div class="ui-grid-a"> |
| 25 | + <div class="ui-block-a"><strong>I'm Block A</strong> and text inside will wrap</div> |
| 26 | + <div class="ui-block-b"><strong>I'm Block B</strong> and text inside will wrap</div> |
| 27 | +</div><!-- /grid-a --> |
| 28 | +</code></pre> |
| 29 | + |
| 30 | + <p>The above markup produces the following content layout:</p> |
| 31 | + <iframe src="/resources/grid-layout/example1.html" style="width:100%;height:90px;border:0"></iframe> |
| 32 | + |
| 33 | + <p>As you see above, by default grid blocks have no visual styling; they simply present content side-by-side.</p> |
| 34 | + <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 container of each of the two buttons inside to stretch them each to 50% of the screen width:</p> |
| 35 | + |
| 36 | +<pre><code> |
| 37 | +<fieldset class="ui-grid-a"> |
| 38 | + <div class="ui-block-a"><button type="submit" data-theme="c">Cancel</button></div> |
| 39 | + <div class="ui-block-b"><button type="submit" data-theme="b">Submit</button></div> |
| 40 | +</fieldset> |
| 41 | +</code></pre> |
| 42 | + |
| 43 | + <iframe src="/resources/grid-layout/example2.html" style="width:100%;height:90px;border:0"></iframe> |
| 44 | + <p>Please note that the framework adds left and right margin to buttons in a grid. For a single button you can use a container with class <code>ui-grid-solo</code> and wrap the button in a div with class <code>ui-block-a</code> like the example below. This way the button will get the same margin.</p> |
| 45 | + |
| 46 | +<pre><code> |
| 47 | +<div class="ui-grid-a"> |
| 48 | + <div class="ui-block-a"><button type="button" data-theme="c">Previous</button></div> |
| 49 | + <div class="ui-block-b"><button type="button" data-theme="c">Next</button></div> |
| 50 | +</div> |
| 51 | +<div class="ui-grid-solo"> |
| 52 | + <div class="ui-block-a"><button type="v" data-theme="b">More</button></div> |
| 53 | +</div> |
| 54 | +</code></pre> |
| 55 | + |
| 56 | + <iframe src="/resources/grid-layout/example3.html" style="width:100%;height:130px;border:0"></iframe> |
| 57 | + |
| 58 | + <p>Theme classes (not data-theme attributes) from the <a href="../api/themes.html" class="ui-link">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 | + |
| 60 | + <iframe src="/resources/grid-layout/example4.html" style="width:100%;height:150px;border:0"></iframe> |
| 61 | + |
| 62 | + <h3>Three-column grids</h3> |
| 63 | + |
| 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 | + |
| 66 | +<pre><code> |
| 67 | +<div class="ui-grid-b"> |
| 68 | + <div class="ui-block-a">Block A</div> |
| 69 | + <div class="ui-block-b">Block B</div> |
| 70 | + <div class="ui-block-c">Block C</div> |
| 71 | +</div><!-- /grid-b --> |
| 72 | +</code></pre> |
| 73 | + |
| 74 | + <p>This will produce a 33/33/33% grid for our content.</p> |
| 75 | + <iframe src="/resources/grid-layout/example5.html" style="width:100%;height:150px;border:0"></iframe> |
| 76 | + |
| 77 | + <p>And an example of a 3 column grid with buttons inside:</p> |
| 78 | + <iframe src="/resources/grid-layout/example6.html" style="width:100%;height:90px;border:0"></iframe> |
| 79 | + |
| 80 | + <h3>Four-column grids</h3> |
| 81 | + |
| 82 | + <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> |
| 83 | + |
| 84 | + <iframe src="/resources/grid-layout/example7.html" style="width:100%;height:150px;border:0"></iframe> |
| 85 | + |
| 86 | + <h2>Five-column grids</h2> |
| 87 | + |
| 88 | + <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 fifth block. Note: These blocks are also styled with theme classes so the grid layout is clearly visible.</p> |
| 89 | + |
| 90 | + <iframe src="/resources/grid-layout/example8.html" style="width:100%;height:150px;border:0"></iframe> |
| 91 | + |
| 92 | + <h3>Multiple row grids</h3> |
| 93 | + |
| 94 | + <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> |
| 95 | + <iframe src="/resources/grid-layout/example9.html" style="width:100%;height:450px;border:0"></iframe> |
| 96 | + |
| 97 | + <h3>Grids in toolbars</h3> |
| 98 | + |
| 99 | + <p>Grids are helpful for creating layouts within a toolbar. Here's a footer with a 4 column grid.</p> |
| 100 | + <iframe src="/resources/grid-layout/example10.html" style="width:100%;height:90px;border:0"></iframe> |
| 101 | + |
| 102 | + </longdesc> |
| 103 | + <added>1.0</added> |
| 104 | + <options> |
| 105 | + </options> |
| 106 | + <events> |
| 107 | + </events> |
| 108 | + <methods> |
| 109 | + </methods> |
| 110 | + <example> |
| 111 | + <desc>A basic example of grid layout</desc> |
| 112 | + <code><![CDATA[]]></code> |
| 113 | + <html><![CDATA[<fieldset class="ui-grid-a"> |
| 114 | + <div class="ui-grid-a"> |
| 115 | + <div class="ui-block-a"><strong>I'm Block A</strong> and text inside will wrap.</div> |
| 116 | + <div class="ui-block-b"><strong>I'm Block B</strong> and text inside will wrap.</div> |
| 117 | + </div><!-- /grid-a -->]]></html> |
| 118 | + </example> |
| 119 | + <category slug="misc"/> |
| 120 | +</entry> |
0 commit comments