5
<title>CSS Grids</title>
6
<link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
7
<link rel="stylesheet" href="../assets/css/main.css">
8
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
9
<script src="../../build/yui/yui-min.js"></script>
17
<a href="#toc" class="jump">Jump to Table of Contents</a>
21
<div id="main" class="yui3-u">
22
<div class="content"> <div class="intro">
24
<p>The foundational CSS Grids provides a simple system for layout out content. The basic components are "grids" and "units". A "grid" (<code>yui3-g</code>) contains one or more "units" (<code>yui3-u</code>). The type of "unit" chosen describes how it should be sized (e.g. "yui3-u-1-2" takes up half the grid, "yui3-u-1-3" takes up one-third, et cetera). The only constrains for YUI3 Grids are that all "units" are children of a "grid". All you need to do is define a grid, one or more units inside it, and specify widths for them. Then stack and nest as required.</p>
27
<h2 id="start">Getting Started</h2>
29
<h3 id="dependencies">Include Dependencies</h3>
31
<p>To use CSS Grids, include the following source file in your web page with the link element.</p>
33
<pre class="code prettyprint"><link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.4.1/build/cssgrids/grids-min.css"></pre>
36
<h2 id="using">Using YUI CSS Grids</h2>
38
<h3 id="unit-sizes">Unit Sizes</h3>
39
<p>All of the sizing for YUI Grids is done using "units". Units can be subdivided up to 1/24 of the available width. The following table gives the various unit classes that can be applied.</p>
49
<td><code>.yui3-u</code></td>
50
<td>Shrinks to fit unless a width is applied.</td>
53
<td><code>.yui3-u-1</code></td>
54
<td>Fills 100% of the available width.</td>
57
<td><code>.yui3-u-1-2</code></td>
58
<td>Fills 1/2 of available width.</td>
61
<td><code>.yui3-u-1-3</code></td>
62
<td>Fills 1/3 of available width.</td>
65
<td><code>.yui3-u-2-3</code></td>
66
<td>Fills 2/3 of available width.</td>
69
<td><code>.yui3-u-1-4</code></td>
70
<td>Fills 1/4 of available width.</td>
73
<td><code>.yui3-u-3-4</code></td>
74
<td>Fills 3/4 of available width.</td>
77
<td><code>.yui3-u-1-5</code></td>
78
<td>Fills 1/5 of available width.</td>
81
<td><code>.yui3-u-2-5</code></td>
82
<td>Fills 2/5 of available width.</td>
85
<td><code>.yui3-u-3-5</code></td>
86
<td>Fills 3/5 of available width.</td>
89
<td><code>.yui3-u-4-5</code></td>
90
<td>Fills 4/5 of available width.</td>
93
<td><code>.yui3-u-1-6</code></td>
94
<td>Fills 1/6 of available width.</td>
97
<td><code>.yui3-u-5-6</code></td>
98
<td>Fills 5/6 of available width.</td>
101
<td><code>.yui3-u-1-8</code></td>
102
<td>Fills 1/8 of available width.</td>
105
<td><code>.yui3-u-3-8</code></td>
106
<td>Fills 3/8 of available width.</td>
109
<td><code>.yui3-u-5-8</code></td>
110
<td>Fills 5/8 of available width.</td>
113
<td><code>.yui3-u-7-8</code></td>
114
<td>Fills 7/8 of available width.</td>
117
<td><code>.yui3-u-1-12</code></td>
118
<td>Fills 1/12 of available width.</td>
121
<td><code>.yui3-u-5-12</code></td>
122
<td>Fills 5/12 of available width.</td>
125
<td><code>.yui3-u-7-12</code></td>
126
<td>Fills 7/12 of available width.</td>
129
<td><code>.yui3-u-11-12</code></td>
130
<td>Fills 11/12 of available width.</td>
133
<td><code>.yui3-u-1-24</code></td>
134
<td>Fills 1/24 of available width.</td>
137
<td><code>.yui3-u-5-24</code></td>
138
<td>Fills 5/24 of available width.</td>
141
<td><code>.yui3-u-7-24</code></td>
142
<td>Fills 7/24 of available width.</td>
145
<td><code>.yui3-u-11-24</code></td>
146
<td>Fills 11/24 of available width.</td>
149
<td><code>.yui3-u-13-24</code></td>
150
<td>Fills 13/24 of available width.</td>
153
<td><code>.yui3-u-17-24</code></td>
154
<td>Fills 17/24 of available width.</td>
157
<td><code>.yui3-u-19-24</code></td>
158
<td>Fills 19/24 of available width.</td>
161
<td><code>.yui3-u-23-24</code></td>
162
<td>Fills 23/24 of available width.</td>
167
<h3 id="page_width">Building a Page Template</h3>
169
<p>The sizing of "units" is done using percentages, so in order to build a "page" template, a width on the outermost container is required. The simplest approach to fixing your page size is to apply a width directly to the body element. Optionally, the page can be centered in the viewport by setting the <code>margin</code> to <code>auto</code>. The following creates a 960px, centered layout.</p>
171
<pre class="code prettyprint">body {
172
margin: auto; /* center in viewport */
177
<p>The next step is to decide on the size of each "column" and choose the appropriate "unit". Remember, units sizes are percentage-based, so a bit of math may be required when designing with pixels rather than proportions. To create a 200 pixel wide sidebar, assuming a 960px layout, we would use a 5/24 unit ("yui3-u-5-24") for the narrow column, and a 19/24 ("yui3-19-24") for the main column.</p>
179
<pre class="code prettyprint"><head>
182
margin: auto; /* center in viewport */
190
<div class="yui3-g">
191
<div class="yui3-u-5-24">
194
<div class="yui3-u-19-24">
198
</body></pre>
200
<h3 id="pixels">Pixel Units</h3>
201
<p>Some layouts have precise sizing requirements that may not always be fulfilled by percentage-based units. Custom unit sizes may be applied using the generic unit ("yui3-u"). Rather than overriding the YUI units, custom sizing should be done using your own semantic markup. To recreate the previous example with custom units, we will add IDs to the column containers. This examples uses "nav" and "main", but these should be tailored to your content.</p>
203
<pre class="code prettyprint"><head>
206
margin: auto; /* center in viewport */
222
<div class="yui3-g">
223
<div class="yui3-u" id="nav">
226
<div class="yui3-u" id="main">
230
</body></pre>
235
<div id="sidebar" class="yui3-u">
237
<div id="toc" class="sidebox">
239
<h2 class="no-toc">Table of Contents</h2>
245
<a href="#start">Getting Started</a>
248
<a href="#dependencies">Include Dependencies</a>
253
<a href="#using">Using YUI CSS Grids</a>
256
<a href="#unit-sizes">Unit Sizes</a>
259
<a href="#page_width">Building a Page Template</a>
262
<a href="#pixels">Pixel Units</a>
272
<div class="sidebox">
274
<h2 class="no-toc">Examples</h2>
278
<ul class="examples">
281
<li data-description="Each unit has a className that provides its percentage width.">
282
<a href="cssgrids-units.html">Using Grid Units</a>
287
<li data-description="This is a template for creating fixed-width layouts.">
288
<a href="cssgrids-fixed.html">Fixed Page Template</a>
293
<li data-description="This is a template for creating fluid layouts.">
294
<a href="cssgrids-fluid.html">Fluid Page Template</a>
299
<li data-description="Basic CSS properties are leveraged to horizontally and vertically align units.">
300
<a href="cssgrids-align.html">Aligning Grid Units</a>
324
<div class="sidebox">
326
<h2 class="no-toc">Examples That Use This Component</h2>
330
<ul class="examples">
341
<li data-description="Creating left navigation using the MenuNav Node Plugin.">
342
<a href="../node-menunav/menunav-leftnav.html">Basic Left Nav</a>
347
<li data-description="Creating top navigation using the MenuNav Node Plugin">
348
<a href="../node-menunav/node-menunav-2.html">Basic Top Nav</a>
353
<li data-description="Creating menu button navigation using the MenuNav Node Plugin">
354
<a href="../node-menunav/node-menunav-3.html">Menu Button Top Nav</a>
359
<li data-description="Creating split button navigation using the MenuNav Node Plugin">
360
<a href="../node-menunav/node-menunav-4.html">Split Button Top Nav</a>
365
<li data-description="Adding shadows to submenus of a left nav using the MenuNav Node Plugin">
366
<a href="../node-menunav/node-menunav-5.html">Left Nav with Submenus with Shadows</a>
371
<li data-description="Adding rounded corners to submenus of a left nav using the MenuNav Node Plugin">
372
<a href="../node-menunav/node-menunav-6.html">Left Nav With Submenus With Rounded Corners</a>
377
<li data-description="Skining a menu built using the MenuNav Node Plugin to look like the menus on Flickr">
378
<a href="../node-menunav/node-menunav-7.html">Skinning Menus Created Using the MenuNav Node Plugin</a>
390
<script src="../assets/vendor/prettify/prettify-min.js"></script>
391
<script>prettyPrint();</script>