5
<title>Example: Aligning Grid Units</title>
6
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Maven+Pro:400,700">
7
<link rel="stylesheet" href="../../build/cssgrids/grids-min.css">
8
<link rel="stylesheet" href="../assets/css/main.css">
9
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
10
<script src="../../build/yui/yui-min.js"></script>
15
<h1>Example: Aligning Grid Units</h1>
20
<div class="yui3-u-3-4">
22
<div class="content"><div class="intro">
23
<p>YUI Grids makes it easy to align units in various ways, using basic CSS properties.</p>
26
<div class="example newwindow">
27
<a href="cssgrids-align-example.html" target="_blank" class="button">
28
View Example in New Window
32
<h3>Horizontal Alignment</h3>
33
<p>Sometimes is it desirable for units to be horizontally centered when taking up less than 100% of the width of the containing grid. Rather than setting the alignment for all grids, we will add an <code>ID</code> to target the specific content being aligned. For this example, the <code>ID</code> "demo" is used, but this should be tailored to your specific content.</p>
35
<pre class="code prettyprint"><div class="yui3-g" id="demo">
36
<div class="yui3-u-1-3"><p>I take up 1/3 of my container.</p></div>
37
<div class="yui3-u-1-3"><p>I take up 1/3 of my container.</p></div>
38
</div></pre>
41
<p>Using the CSS <code>text-align</code> property on the containing grid tells the units inside of a grid how to align. We will also reset the centering so that subsequent content is left-aligned.</p>
43
<pre class="code prettyprint"><style>
51
</style></pre>
54
<h3>Vertical Alignment</h3>
55
<p>Vertical alignment tells mixed height units how they should align relative to one another, so at least 2 units are required.</p>
57
<pre class="code prettyprint"><div class="yui3-g thumb-captions">
58
<div class="yui3-u-1-3">
59
<a href="#"><img width="80" height="60" src="museum.jpg">
63
<div class="yui3-u-1-3">
64
<a href="#"><img height="80" width="60" src="museum.jpg">
68
<div class="yui3-u-1-3">
69
<a href="#"><img height="80" width="60" src="museum.jpg">
73
</div></pre>
76
<p>Each unit needs to be told how it should align using the CSS <code>vertical-align</code> property. In this case, we want them all to be bottom aligned.</p>
78
<pre class="code prettyprint"><style>
79
.thumb-captions .yui3-u-1-3 {
80
vertical-align: bottom;
82
</style></pre>
85
<h3>Vertically Center a Single Unit</h3>
86
<p>Its possible to vertically center a single unit, although a second stub unit is required for it to align with.</p>
88
<pre class="code prettyprint"><div class="yui3-g" id="demo">
89
<div class="yui3-u align-stub"></div>
90
<div class="yui3-u-1-3">
91
<p>Cras porta venenatis egestas. Vestibulum pretium massa id turpis varius iaculis.</p>
93
</div></pre>
96
<p>Setting the height of the stub to the desired height of the container allows the content to align with the middle of the stub, vertically centered in the container. Setting the <code>vertical-align</code> CSS property for both units tells them how to behave with repsect to the other units.</p>
98
<pre class="code prettyprint"><style>
105
vertical-align: middle;
107
</style></pre>
111
<p>Because CSS examples are susceptible to other CSS on the page, this example is only available in a new window at the above link.</p>
116
<div class="yui3-u-1-4">
117
<div class="sidebar">
121
<div class="sidebox">
123
<h2 class="no-toc">Examples</h2>
127
<ul class="examples">
130
<li data-description="Each unit has a className that provides its percentage width.">
131
<a href="cssgrids-units.html">Using Grid Units</a>
136
<li data-description="This is a template for creating fixed-width layouts.">
137
<a href="cssgrids-fixed.html">Fixed Page Template</a>
142
<li data-description="This is a template for creating fluid layouts.">
143
<a href="cssgrids-fluid.html">Fluid Page Template</a>
148
<li data-description="Basic CSS properties are leveraged to horizontally and vertically align units.">
149
<a href="cssgrids-align.html">Aligning Grid Units</a>
173
<div class="sidebox">
175
<h2 class="no-toc">Examples That Use This Component</h2>
179
<ul class="examples">
190
<li data-description="Creating left navigation using the MenuNav Node Plugin.">
191
<a href="../node-menunav/menunav-leftnav.html">Basic Left Nav</a>
196
<li data-description="Creating top navigation using the MenuNav Node Plugin">
197
<a href="../node-menunav/node-menunav-2.html">Basic Top Nav</a>
202
<li data-description="Creating menu button navigation using the MenuNav Node Plugin">
203
<a href="../node-menunav/node-menunav-3.html">Menu Button Top Nav</a>
208
<li data-description="Creating split button navigation using the MenuNav Node Plugin">
209
<a href="../node-menunav/node-menunav-4.html">Split Button Top Nav</a>
214
<li data-description="Adding shadows to submenus of a left nav using the MenuNav Node Plugin">
215
<a href="../node-menunav/node-menunav-5.html">Left Nav with Submenus with Shadows</a>
220
<li data-description="Adding rounded corners to submenus of a left nav using the MenuNav Node Plugin">
221
<a href="../node-menunav/node-menunav-6.html">Left Nav With Submenus With Rounded Corners</a>
226
<li data-description="Skining a menu built using the MenuNav Node Plugin to look like the menus on Flickr">
227
<a href="../node-menunav/node-menunav-7.html">Skinning Menus Created Using the MenuNav Node Plugin</a>
240
<script src="../assets/vendor/prettify/prettify-min.js"></script>
241
<script>prettyPrint();</script>