Permalink
Browse files

[grid] Added responsive docs page and "ui-responsive" breakpoint pres…

…et. Fixes #4955

Also updated all content docs to link to the new page, linked it up to
the search index
  • Loading branch information...
1 parent dd48379 commit b124d3e3d196647e0e1dc73eab3cf0dcd69dbd24 @toddparker toddparker committed Nov 18, 2012
@@ -21,3 +21,15 @@
.ui-grid-d .ui-block-a, .ui-grid-d .ui-block-b, .ui-grid-d .ui-block-c, .ui-grid-d .ui-block-d, .ui-grid-d .ui-block-e { width: 19.925%; }
.ui-grid-d > :nth-child(n) { width: 20%; }
.ui-grid-d .ui-block-a { clear: left; }
+
+/* preset breakpoint to switch to stacked grid styles below 35em (560px) */
+@media all and (max-width: 35em) {
+ .ui-responsive .ui-block-a,
+ .ui-responsive .ui-block-b,
+ .ui-responsive .ui-block-c,
+ .ui-responsive .ui-block-d,
+ .ui-responsive .ui-block-e {
+ width: 100%;
+ float:none;
+ }
+}
@@ -89,6 +89,7 @@
<li data-role="list-divider">Content Formatting</li>
<li><a href="content-html.html">Basic HTML styles</a></li>
<li><a href="content-grids.html">Layout grids (columns)</a></li>
+ <li><a href="content-grids-responsive.html">Responsive grids</a></li>
<li data-theme="a"><a href="content-collapsible.html">Collapsible content blocks</a></li>
<li><a href="content-collapsible-set.html">Collapsible sets (accordions)</a></li>
<li><a href="content-themes.html">Theming content</a></li>
@@ -62,6 +62,7 @@
<li data-role="list-divider">Content Formatting</li>
<li><a href="content-html.html">Basic HTML styles</a></li>
<li><a href="content-grids.html">Layout grids (columns)</a></li>
+ <li><a href="content-grids-responsive.html">Responsive grids</a></li>
<li data-theme="a"><a href="content-collapsible.html">Collapsible content blocks</a></li>
<li><a href="content-collapsible-set.html">Collapsible sets (accordions)</a></li>
<li><a href="content-themes.html">Theming content</a></li>
@@ -192,6 +192,7 @@
<li data-role="list-divider">Content Formatting</li>
<li><a href="content-html.html">Basic HTML styles</a></li>
<li><a href="content-grids.html">Layout grids (columns)</a></li>
+ <li><a href="content-grids-responsive.html">Responsive grids</a></li>
<li data-theme="a"><a href="content-collapsible.html">Collapsible content blocks</a></li>
<li><a href="content-collapsible-set.html">Collapsible sets (accordions)</a></li>
<li><a href="content-themes.html">Theming content</a></li>
@@ -69,6 +69,7 @@
<li data-role="list-divider">Content Formatting</li>
<li><a href="content-html.html">Basic HTML styles</a></li>
<li><a href="content-grids.html">Layout grids (columns)</a></li>
+ <li><a href="content-grids-responsive.html">Responsive grids</a></li>
<li><a href="content-collapsible.html">Collapsible content blocks</a></li>
<li data-theme="a"><a href="content-collapsible-set.html">Collapsible sets (accordions)</a></li>
<li><a href="content-themes.html">Theming content</a></li>
@@ -65,6 +65,7 @@
<li data-role="list-divider">Content Formatting</li>
<li><a href="content-html.html">Basic HTML styles</a></li>
<li><a href="content-grids.html">Layout grids (columns)</a></li>
+ <li><a href="content-grids-responsive.html">Responsive grids</a></li>
<li><a href="content-collapsible.html">Collapsible content blocks</a></li>
<li data-theme="a"><a href="content-collapsible-set.html">Collapsible sets (accordions)</a></li>
<li><a href="content-themes.html">Theming content</a></li>
@@ -125,6 +125,7 @@
<li data-role="list-divider">Content Formatting</li>
<li><a href="content-html.html">Basic HTML styles</a></li>
<li><a href="content-grids.html">Layout grids (columns)</a></li>
+ <li><a href="content-grids-responsive.html">Responsive grids</a></li>
<li><a href="content-collapsible.html">Collapsible content blocks</a></li>
<li data-theme="a"><a href="content-collapsible-set.html">Collapsible sets (accordions)</a></li>
<li><a href="content-themes.html">Theming content</a></li>
@@ -216,6 +216,7 @@
<li data-role="list-divider">Content Formatting</li>
<li><a href="content-html.html">Basic HTML styles</a></li>
<li><a href="content-grids.html">Layout grids (columns)</a></li>
+ <li><a href="content-grids-responsive.html">Responsive grids</a></li>
<li><a href="content-collapsible.html">Collapsible content blocks</a></li>
<li data-theme="a"><a href="content-collapsible-set.html">Collapsible sets (accordions)</a></li>
<li><a href="content-themes.html">Theming content</a></li>
@@ -229,6 +229,7 @@
<li data-role="list-divider">Content Formatting</li>
<li><a href="content-html.html">Basic HTML styles</a></li>
<li><a href="content-grids.html">Layout grids (columns)</a></li>
+ <li><a href="content-grids-responsive.html">Responsive grids</a></li>
<li data-theme="a"><a href="content-collapsible.html">Collapsible content blocks</a></li>
<li><a href="content-collapsible-set.html">Collapsible sets (accordions)</a></li>
<li><a href="content-themes.html">Theming content</a></li>
@@ -0,0 +1,200 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>jQuery Mobile Docs - Content Grids</title>
+ <link rel="stylesheet" href="../../css/themes/default/jquery.mobile.css" />
+ <link rel="stylesheet" href="../_assets/css/jqm-docs.css"/>
+
+ <script src="../../js/jquery.js"></script>
+ <script src="../../docs/_assets/js/jqm-docs.js"></script>
+ <script src="../../js/"></script>
+
+</head>
+<body>
+
+ <div data-role="page" class="type-interior">
+
+ <div data-role="header" data-theme="f">
+ <h1>RWD grids</h1>
+ <a href="../../" data-icon="home" data-iconpos="notext" data-direction="reverse">Home</a>
+ <a href="../nav.html" data-icon="search" data-iconpos="notext" data-rel="dialog" data-transition="fade">Search</a>
+ </div><!-- /header -->
+
+ <div data-role="content">
+ <div class="content-primary">
+
+ <h2>Responsive grids</h2>
+ <p>When using <a href="content-grids.html">layout grids</a> for building full-level layouts, it may make sense to apply responsive web design (RWD) principles to ensure that the layout adapts to a wide range screen widths.</p>
+ <p>The simplest form of responsive behavior swaps from a stacked layout on narrow screens like a smartphone to the multi-column grid layouts at wider screens. This can be done by targeting styles to specific screen widths by using CSS media queries.</p>
+
+ <h2>Making the grids responsive</h2>
+ <p>By default, the grid classes will result in a multi column layout across all all screen widths. The styles to make the grids responsive are added by applying a media query with rules to switch to the stacked style presentation below a specific screen width.</p>
+
+ <p>We normally recommend starting with mobile-first approach for media queries: starting with the styles that apply to the smallest screen sizes in the core widget styles, then progressively layering breakpoints up to larger screens by using <code>min-width</code> media queries.</p>
+ <p>However, in the case of grids we can use a <code>max-width</code> media query to only only apply the stacked grid styles <em>below</em> a width breakpoint. This allows us to leverage all the default grid styles but just tweak them at narrow widths.</p>
+
+
+ <p>Without the custom styles, our grid will be a 3 column layout across all screen widths:</p>
+ <div class="ui-grid-b">
+ <div class="ui-block-a"><div class="ui-body ui-body-d">Block A</div></div>
+ <div class="ui-block-b"><div class="ui-body ui-body-d">Block B</div></div>
+ <div class="ui-block-c"><div class="ui-body ui-body-d">Block C</div></div>
+ </div><!-- /grid-b -->
+
+ <p>In our custom styles, we want this grid to stack at narrow widths, then switch to a standard 3 column layout. At very wide screen widths, we want first column to take up 50% of the width, like this:</p>
+
+ <div class="ui-grid-b my-breakpoint">
+ <div class="ui-block-a"><div class="ui-body ui-body-d">Block A</div></div>
+ <div class="ui-block-b"><div class="ui-body ui-body-d">Block B</div></div>
+ <div class="ui-block-c"><div class="ui-body ui-body-d">Block C</div></div>
+ </div><!-- /grid-b -->
+
+ <p>To make this responsive, start by adding the <code>my-breakpoint</code> class to the grid container that references the custom breakpoint in your custom stylesheet:</p>
+
+<pre><code>
+&lt;div class=&quot;ui-grid-b <strong>my-breakpoint</strong>&quot;&gt;
+ &lt;div class=&quot;ui-block-a&quot;&gt;Block A&lt;/div&gt;
+ &lt;div class=&quot;ui-block-b&quot;&gt;Block B&lt;/div&gt;
+ &lt;div class=&quot;ui-block-c&quot;&gt;Block C&lt;/div&gt;
+&lt;/div&gt;&lt;!-- /grid-b --&gt;
+</code></pre>
+
+ <h3>Adding the stack breakpoint at narrow widths</h3>
+
+ <p>This class is used to scope the styles within the custom media query so they will only apply when this class is added to the grid container. The media query wraps the conditional styles we only want applied below 50em. </p>
+ <p>In your media queries, use em units instead of pixels to ensure that the media query will take font size into account in addition to just screen width. To calculate a screen widths in ems, divide the target width in pixels by 16 which is the default font size of the body.</p>
+
+<pre><code>
+<strong>@media all and (max-width: 50em) {</strong>
+ .my-breakpoint .ui-block-a,
+ .my-breakpoint .ui-block-b,
+ .my-breakpoint .ui-block-c,
+ .my-breakpoint .ui-block-d,
+ .my-breakpoint .ui-block-e {
+ width: 100%;
+ float:none;
+ }
+<strong>}</strong>
+</code></pre>
+
+ <p>Within this media query, we set the width to 100% and negate the float property to make the grid blocks stack below 50em screen widths. These rules are applied to every <a href="content-grids.html">grid type</a> by stacking up selectors for all the grid classes from <code>ui-block-a</code> to <code>ui-block-e</code> on the styles.</p>
+
+ <style>
+ @media all and (max-width: 50em) {
+ .my-breakpoint .ui-block-a,
+ .my-breakpoint .ui-block-b,
+ .my-breakpoint .ui-block-c,
+ .my-breakpoint .ui-block-d,
+ .my-breakpoint .ui-block-e {
+ width: 100%;
+ float:none;
+ }
+ }
+
+ @media all and (min-width: 75em) {
+ .my-breakpoint.ui-grid-b .ui-block-a { width: 49.95%; }
+ .my-breakpoint.ui-grid-b .ui-block-b,
+ .my-breakpoint.ui-grid-b .ui-block-c { width: 24.925%; }
+ }
+ }
+ </style>
+
+ <p>That is all it takes to make grids responsive and it's easy to add additional styling rules to each breakpoint to change it up even more. We encourage you to create as many custom breakpoints as you need based on your unique content and layout needs.</p>
+
+ <h3>Adding a widescreen breakpoint to adjust ratios</h3>
+
+ <p>Building on the example above, we can add an additional breakpoint to shift the widths to make the first column 50% width and the other two 25% above 75em (1,200 pixels) by layering an additional <code>min-width</code> media query to tweak widths in our custom style like this:</p>
+
+ <pre><code>
+<strong>@media all and (min-width: 75em) {</strong>
+ .my-breakpoint.ui-grid-b .ui-block-a { width: 49.95%; }
+ .my-breakpoint.ui-grid-b .ui-block-b,
+ .my-breakpoint.ui-grid-b .ui-block-c { width: 24.925%; }
+ .my-breakpoint.ui-grid-b .ui-block-a { clear: left; }
+ }
+<strong>}
+</strong> </code></pre>
+ <p>Note the slightly narrower widths set to work around rounding issues across platforms. </p>
+
+
+ <h2>Applying a preset breakpoint</h2>
+ <p>Even though we strongly encourage you to write custom breakpoints yourself, the framework includes a single pre-configured breakpoint that targets the stacked style to smaller phones and swaps to the multi-column presentation on larger phones, tablet and desktop devices. </p>
+ <p>To use this preset breakpoint, add the <code>ui-responsive</code> class to the grid container to apply the stacked presentation <em>below</em> 560px (35em). If this breakpoint doesn't work for your content, we encourage you to write a custom breakpoint as described above.</p>
+
+ <pre><code>&lt;div class=&quot;ui-grid-b <strong>ui-responsive</strong>&quot;&gt;</code></pre>
+
+ <p>These are standard grids that are made responsive by <code>ui-responsive</code> class to the grid container:</p>
+
+
+ <h3>Grid A (50/50)</h3>
+
+ <div class="ui-grid-a ui-responsive">
+ <div class="ui-block-a"><div class="ui-body ui-body-d">Block A</div></div>
+ <div class="ui-block-b"><div class="ui-body ui-body-d">Block B</div></div>
+ </div><!-- /grid-a -->
+
+
+ <h3>Grid B (33/33/33)</h3>
+
+ <div class="ui-grid-b ui-responsive">
+ <div class="ui-block-a"><div class="ui-body ui-body-d">Block A</div></div>
+ <div class="ui-block-b"><div class="ui-body ui-body-d">Block B</div></div>
+ <div class="ui-block-c"><div class="ui-body ui-body-d">Block C</div></div>
+ </div><!-- /grid-b -->
+
+
+ <h3>Grid C (25/25/25/25)</h3>
+
+ <div class="ui-grid-c ui-responsive">
+ <div class="ui-block-a"><div class="ui-body ui-body-d">A</div></div>
+ <div class="ui-block-b"><div class="ui-body ui-body-d">B</div></div>
+ <div class="ui-block-c"><div class="ui-body ui-body-d">C</div></div>
+ <div class="ui-block-d"><div class="ui-body ui-body-d">D</div></div>
+ </div><!-- /grid-c -->
+
+
+ <h3>Grid D (20/20/20/20/20)</h3>
+
+ <div class="ui-grid-d ui-responsive">
+ <div class="ui-block-a"><div class="ui-body ui-body-d">A</div></div>
+ <div class="ui-block-b"><div class="ui-body ui-body-d">B</div></div>
+ <div class="ui-block-c"><div class="ui-body ui-body-d">C</div></div>
+ <div class="ui-block-d"><div class="ui-body ui-body-d">D</div></div>
+ <div class="ui-block-e"><div class="ui-body ui-body-d">E</div></div>
+ </div><!-- /grid-d -->
+
+ </div><!--/content-primary -->
+
+ <div class="content-secondary">
+
+ <div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
+
+ <h3>More in this section</h3>
+
+ <ul data-role="listview" data-theme="c" data-dividertheme="d">
+
+ <li data-role="list-divider">Content Formatting</li>
+ <li><a href="content-html.html">Basic HTML styles</a></li>
+ <li><a href="content-grids.html">Layout grids (columns)</a></li>
+ <li data-theme="a"><a href="content-grids-responsive.html">Responsive grids</a></li>
+ <li><a href="content-collapsible.html">Collapsible content blocks</a></li>
+ <li><a href="content-collapsible-set.html">Collapsible sets (accordions)</a></li>
+ <li><a href="content-themes.html">Theming content</a></li>
+
+ </ul>
+ </div>
+ </div>
+
+</div><!-- /content -->
+
+<div data-role="footer" class="footer-docs" data-theme="c">
+ <p class="jqm-version"></p>
+ <p>&copy; 2012 jQuery Foundation and other contributors</p>
+</div>
+
+</div><!-- /page -->
+
+</body>
+</html>
@@ -17,14 +17,15 @@
<div data-role="page" class="type-interior">
<div data-role="header" data-theme="f">
- <h1>Layout grids</h1>
+ <h1>Grids</h1>
<a href="../../" data-icon="home" data-iconpos="notext" data-direction="reverse">Home</a>
<a href="../nav.html" data-icon="search" data-iconpos="notext" data-rel="dialog" data-transition="fade">Search</a>
</div><!-- /header -->
<div data-role="content">
<div class="content-primary">
+ <h2>Layout grids</h2>
<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>
<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>
@@ -169,17 +170,8 @@
</div><!-- /grid-c -->
- <h2>Grids in toolbars</h2>
- <p>Grids are helpful for creating layouts within a toolbar. Here's a footer with a 4 column grid.</p>
- <!-- NOTE: Inline styles are for demo purposes only, please use external styles -->
- <div data-role="footer" data-theme="a" class="ui-bar ui-grid-c">
- <div class="ui-block-a"><h3 style="margin-top:10px;">Settings</h3></div>
- <div class="ui-block-b"><label for="value" style="margin:8px 10px 0 0; text-align:right;">Price</label></div>
- <div class="ui-block-c"><input id="value" value="5,000"></div>
- <div class="ui-block-d">
- <div style="margin:6px 0 0 10px;"><button type="submit" data-theme="b">Update</button></div>
- </div>
- </div><!-- /footer -->
+ <h2>Making responsive grids</h2>
+ <p>Grids can be made responsive so they adapt to various screen widths which is useful if used for building full page layouts. Learn more in the <a href="content-grids-responsive.html">responsive grids</a>.</p>
</div><!--/content-primary -->
@@ -195,6 +187,7 @@
<li data-role="list-divider">Content Formatting</li>
<li><a href="content-html.html">Basic HTML styles</a></li>
<li data-theme="a"><a href="content-grids.html">Layout grids (columns)</a></li>
+ <li><a href="content-grids-responsive.html">Responsive grids</a></li>
<li><a href="content-collapsible.html">Collapsible content blocks</a></li>
<li><a href="content-collapsible-set.html">Collapsible sets (accordions)</a></li>
<li><a href="content-themes.html">Theming content</a></li>
@@ -124,6 +124,7 @@
<li data-role="list-divider">Content Formatting</li>
<li data-theme="a"><a href="content-html.html">Basic HTML styles</a></li>
<li><a href="content-grids.html">Layout grids (columns)</a></li>
+ <li><a href="content-grids-responsive.html">Responsive grids</a></li>
<li><a href="content-collapsible.html">Collapsible content blocks</a></li>
<li><a href="content-collapsible-set.html">Collapsible sets (accordions)</a></li>
<li><a href="content-themes.html">Theming content</a></li>
@@ -137,6 +137,7 @@
<li data-role="list-divider">Content Formatting</li>
<li><a href="content-html.html">Basic HTML styles</a></li>
<li><a href="content-grids.html">Layout grids (columns)</a></li>
+ <li><a href="content-grids-responsive.html">Responsive grids</a></li>
<li><a href="content-collapsible.html">Collapsible content blocks</a></li>
<li><a href="content-collapsible-set.html">Collapsible sets (accordions)</a></li>
<li data-theme="a"><a href="content-themes.html">Theming content</a></li>
@@ -40,6 +40,7 @@
<li data-role="list-divider">Content Formatting</li>
<li><a href="content-html.html">Basic HTML styles</a></li>
<li><a href="content-grids.html">Layout grids (columns)</a></li>
+ <li><a href="content-grids-responsive.html">Responsive grids</a></li>
<li><a href="content-collapsible.html">Collapsible content blocks</a></li>
<li><a href="content-collapsible-set.html">Collapsible sets (accordions)</a></li>
<li><a href="content-themes.html">Theming content</a></li>
View
@@ -249,6 +249,9 @@
<li data-filtertext="refresh forms elements property change update programatically checked selectedindex value update widget input text slider switch select button checkbox radiobutton">
<a href="forms/docs-forms.html">Refreshing form elements</a>
</li>
+ <li data-filtertext="grids, rwd, breakpoints, layout">
+ <a href="content/content-grids-responsive.html">Responsive grids</a>
+ </li>
<li data-filtertext="scripting pages loading scripts executing scripts document.ready() api developer firing fire pagecreate pageinit changing pages loading enhancing create refresh scolling silentscroll binding to mouse touch events passing url parameters backbone router">
<a href="pages/page-scripting.html">Scripting pages</a>
</li>

0 comments on commit b124d3e

Please sign in to comment.