|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Left Nav With Submenus With Rounded Corners</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
<h1>Example: Left Nav With Submenus With Rounded Corners</h1> |
|
|
25 |
<div class="yui3-g"> |
|
|
26 |
<div class="yui3-u-3-4"> |
|
|
27 |
<div id="main"> |
|
|
28 |
<div class="content"><div class="intro"> |
|
|
29 |
<p> |
|
|
30 |
This example demonstrates how to add rounded corners to submenus of a menu built using the |
|
|
31 |
MenuNav Node Plugin. |
|
|
32 |
</p> |
|
|
33 |
</div> |
|
|
34 |
|
|
|
35 |
<div class="example newwindow"> |
|
|
36 |
<a href="node-menunav-6-example.html" target="_blank" class="button"> |
|
|
37 |
View Example in New Window |
|
|
38 |
</a> |
|
|
39 |
</div> |
|
|
40 |
|
|
|
41 |
<h2>Creating the Rounded Corner HTML</h2> |
|
|
42 |
<p> |
|
|
43 |
<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the |
|
|
44 |
page's <code><body></code> element or to a parent element of the widget in order to apply |
|
|
45 |
the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>. |
|
|
46 |
</p> |
|
|
47 |
<pre class="code prettyprint"><body class="yui3-skin-sam"> <!-- You need this skin class --></pre> |
|
|
48 |
|
|
|
49 |
<p> |
|
|
50 |
One way to add rounded corners to submenus is to append decorator elements to the node representing |
|
|
51 |
a submenu's bounding box. As the name implies, decorator elements add no semantic value to the |
|
|
52 |
markup, but enable additional styles to be applied. When adding any decorator elements to create |
|
|
53 |
effects like shadows or rounded corners, always add those elements via JavaScript, since it is only |
|
|
54 |
when JavaScript is enabled that a menu's markup is transformed in a drop-down menu system via the |
|
|
55 |
MenuNav Node Plugin. |
|
|
56 |
</p> |
|
|
57 |
|
|
|
58 |
<p> |
|
|
59 |
Each rounded corner is created by applying a background image to a <code><div></code>. |
|
|
60 |
A class name identifying the corner will be added to each <code><div></code>. |
|
|
61 |
The <code><div></code>s used to create the right corners will be nested inside the |
|
|
62 |
<code><div></code>s used to create the left corners, and each <code><div></code> |
|
|
63 |
for the left corners will have an additional class name of <code>yui3-menu-corner</code>. The |
|
|
64 |
template for each set of rounded corners comes together as follows: |
|
|
65 |
</p> |
|
|
66 |
|
|
|
67 |
<pre class="code prettyprint"><!-- top-left and top-right corners --> |
|
|
68 |
<div class="yui3-menu-corner yui3-menu-corner-tl"><div class="yui3-menu-corner-tr"></div></div> |
|
|
69 |
|
|
|
70 |
<!-- bottom-left and bottom-right corners --> |
|
|
71 |
<div class="yui3-menu-corner yui3-menu-corner-bl"><div class="yui3-menu-corner-br"></div></div></pre> |
|
|
72 |
|
|
|
73 |
|
|
|
74 |
<p> |
|
|
75 |
The <code><div></code>s for each corner is created by passing a string |
|
|
76 |
of HTML to Node's <a href="http://yuilibrary.com/yui/docs/api/classes/Node.html#method_create"><code>create</code></a> method. Use |
|
|
77 |
the <a href="http://yuilibrary.com/yui/docs/api/classes/Node.html#method_all"><code>all</code></a> method to |
|
|
78 |
retrieve Node instances for each submenu, and the |
|
|
79 |
<a href="http://yuilibrary.com/yui/docs/api/classes/Node.html#method_append"><code>append</code></a> and |
|
|
80 |
<a href="http://yuilibrary.com/yui/docs/api/classes/Node.html#method_prepend"><code>prepend</code></a> |
|
|
81 |
methods to add the rounded corners <code><div></code>s to the bounding box of each submenu. |
|
|
82 |
</p> |
|
|
83 |
|
|
|
84 |
<pre class="code prettyprint">// Call the "use" method, passing in "node-menunav". This will load the |
|
|
85 |
// script and CSS for the MenuNav Node Plugin and all of the required |
|
|
86 |
// dependencies. |
|
|
87 |
|
|
|
88 |
YUI().use('node-menunav', function(Y) { |
|
|
89 |
|
|
|
90 |
// Retrieve the Node instance representing the root menu |
|
|
91 |
// (<div id="productsandservices">) |
|
|
92 |
|
|
|
93 |
var menu = Y.one("#productsandservices"); |
|
|
94 |
|
|
|
95 |
|
|
|
96 |
// Use the "all" method to retrieve the |
|
|
97 |
// Node instances representing each submenu. |
|
|
98 |
|
|
|
99 |
menu.all(".yui3-menu").each(function (node) { |
|
|
100 |
|
|
|
101 |
// Add decorator elements used to create the rounded corners to the |
|
|
102 |
// bounding box of each submenu. |
|
|
103 |
|
|
|
104 |
// Insert the first decorator before the submenu's content box |
|
|
105 |
node.prepend('<div class="yui3-menu-corner yui3-menu-corner-tl"><div class="yui3-menu-corner-tr"></div></div>'); |
|
|
106 |
|
|
|
107 |
// Insert the second decorator after the submenu's content box |
|
|
108 |
node.append('<div class="yui3-menu-corner yui3-menu-corner-bl"><div class="yui3-menu-corner-br"></div></div>'); |
|
|
109 |
|
|
|
110 |
}); |
|
|
111 |
|
|
|
112 |
|
|
|
113 |
// Call the "plug" method of the Node instance, passing in a reference to the |
|
|
114 |
// MenuNav Node Plugin. |
|
|
115 |
|
|
|
116 |
menu.plug(Y.Plugin.NodeMenuNav); |
|
|
117 |
|
|
|
118 |
// Show the menu now that it is ready |
|
|
119 |
|
|
|
120 |
menu.get("ownerDocument").get("documentElement").removeClass("yui3-loading"); |
|
|
121 |
|
|
|
122 |
});</pre> |
|
|
123 |
|
|
|
124 |
<em>Note:</em> In keeping with the |
|
|
125 |
<a href="http://developer.yahoo.com/performance/">Exceptional Performance</a> |
|
|
126 |
team's recommendation, the script block used to instantiate the menu will be |
|
|
127 |
<a href="http://developer.yahoo.com/performance/rules.html#js_bottom">placed at the bottom of the page</a>. |
|
|
128 |
This not only improves performance, it helps ensure that the DOM subtree of the |
|
|
129 |
element representing the root menu |
|
|
130 |
(<code><div id="productsandservices"></code>) is ready to be scripted. |
|
|
131 |
</p> |
|
|
132 |
|
|
|
133 |
<h2>Create the Rounded Corner Background Image</h2> |
|
|
134 |
<p> |
|
|
135 |
For performance, each rounded corner <code><div></code> uses the same image as its |
|
|
136 |
background image, but only reveals the relevant section of the image via the |
|
|
137 |
<code>background-position</code> property. The complete image is as follows: |
|
|
138 |
</p> |
|
|
139 |
|
|
|
140 |
<img src="../assets/node-menunav/round.png" width="200" height="6" alt="Image used as the background image for the DIV elements used to create rounded corners"> |
|
|
141 |
|
|
|
142 |
<h2>Styling the Rounded Corner HTML</h2> |
|
|
143 |
<p> |
|
|
144 |
With the rounded corner elements appended to each submenu, the next step is to define |
|
|
145 |
the styles that create the rounded corner effect. Start by overriding the values for |
|
|
146 |
<code>border</code> and <code>padding</code> specified for the content box of each submenu in the |
|
|
147 |
Sam skin CSS. The top and bottom borders are set to 0, since both borders will be drawn by the |
|
|
148 |
background image used to create the rounded corners. The top and bottom padding will be created by |
|
|
149 |
setting the height of each <code><div></code> inside the |
|
|
150 |
<code><div class="yui3-menu-corner"></code>. |
|
|
151 |
</p> |
|
|
152 |
|
|
|
153 |
<pre class="code prettyprint">/* |
|
|
154 |
Overide the values for border and padding specified for the content box of each submenu in |
|
|
155 |
the Sam skin CSS. The top and bottom borders are set to 0, since both borders will be drawn |
|
|
156 |
by the background image used to create the rounded corners. The top and bottom padding |
|
|
157 |
will be created by setting the height of each <div> inside the |
|
|
158 |
<div class="yui3-menu-corner">. |
|
|
159 |
*/ |
|
|
160 |
|
|
|
161 |
#productsandservices .yui3-menu .yui3-menu-content { |
|
|
162 |
|
|
|
163 |
border-top: 0; |
|
|
164 |
border-bottom: 0; |
|
|
165 |
padding: 0; |
|
|
166 |
|
|
|
167 |
}</pre> |
|
|
168 |
|
|
|
169 |
|
|
|
170 |
<p> |
|
|
171 |
Next, define the styles for each corner element. The <code><div></code>s for the top-left |
|
|
172 |
and bottom-left corners define a right margin that will provide space for the their inner |
|
|
173 |
<code><div></code>s to fill using a negative right margin. Each inner |
|
|
174 |
<code><div></code> will define a left margin to reveal the background image applied to |
|
|
175 |
its parent <code><div></code>. |
|
|
176 |
</p> |
|
|
177 |
<pre class="code prettyprint">.yui3-menu-corner { |
|
|
178 |
|
|
|
179 |
margin-right: 4px; /* Reserve space for the top-right and bottom-right corners. */ |
|
|
180 |
|
|
|
181 |
/* The background image (sprite) for the top-left and bottom-left corners. */ |
|
|
182 |
background: url(../assets/node-menunav/round.png) no-repeat; |
|
|
183 |
|
|
|
184 |
} |
|
|
185 |
|
|
|
186 |
.yui3-menu-corner div { |
|
|
187 |
|
|
|
188 |
height: 4px; |
|
|
189 |
|
|
|
190 |
margin: 0 -4px 0 4px; /* Use a negative right margin to move the <div> into |
|
|
191 |
the right margin of the parent element |
|
|
192 |
(<div class="yui3-menu-corner">) to draw the top-right |
|
|
193 |
and bottom-right corners. |
|
|
194 |
|
|
|
195 |
Apply a left margin to reveal the background image |
|
|
196 |
applied to the parent element for the top-left and |
|
|
197 |
bottom-left corners. */ |
|
|
198 |
|
|
|
199 |
/* The background image (sprite) for the top-right and bottom-right corners. */ |
|
|
200 |
background: url(../assets/node-menunav/round.png) no-repeat; |
|
|
201 |
|
|
|
202 |
_position: relative; /* Necessary to get negative margins working in IE 6 |
|
|
203 |
(Standards Mode and Quirks Mode and IE 7 (Quirks |
|
|
204 |
Mode only). */ |
|
|
205 |
|
|
|
206 |
_font-size: 0; /* Necessary to collapse the height of the <div> in IE 6 |
|
|
207 |
(Standards Mode and Quirks Mode and IE 7 (Quirks Mode only) so |
|
|
208 |
that it renders at 4px tall. */ |
|
|
209 |
|
|
|
210 |
}</pre> |
|
|
211 |
|
|
|
212 |
|
|
|
213 |
<p> |
|
|
214 |
The last step is to simply set <code>background-position</code> property for the bottom-left, |
|
|
215 |
top-right, and bottom-right corner elements to reveal the corresponding section of the corner |
|
|
216 |
background image. |
|
|
217 |
</p> |
|
|
218 |
<pre class="code prettyprint">/* |
|
|
219 |
Set the "background-position" property for the bottom-left, top-right, and |
|
|
220 |
bottom-right corner elements to reveal the corresponding section of the corner |
|
|
221 |
background image. |
|
|
222 |
*/ |
|
|
223 |
|
|
|
224 |
.yui3-menu-corner-bl { |
|
|
225 |
|
|
|
226 |
background-position: left bottom; |
|
|
227 |
|
|
|
228 |
} |
|
|
229 |
|
|
|
230 |
.yui3-menu-corner .yui3-menu-corner-tr { |
|
|
231 |
|
|
|
232 |
background-position: top right; |
|
|
233 |
|
|
|
234 |
} |
|
|
235 |
|
|
|
236 |
.yui3-menu-corner .yui3-menu-corner-br { |
|
|
237 |
|
|
|
238 |
background-position: right bottom; |
|
|
239 |
|
|
|
240 |
}</pre> |
|
|
241 |
|
|
|
242 |
</div> |
|
|
243 |
</div> |
|
|
244 |
</div> |
|
|
245 |
|
|
|
246 |
<div class="yui3-u-1-4"> |
|
|
247 |
<div class="sidebar"> |
|
|
248 |
|
|
|
249 |
|
|
|
250 |
|
|
|
251 |
<div class="sidebox"> |
|
|
252 |
<div class="hd"> |
|
|
253 |
<h2 class="no-toc">Examples</h2> |
|
|
254 |
</div> |
|
|
255 |
|
|
|
256 |
<div class="bd"> |
|
|
257 |
<ul class="examples"> |
|
|
258 |
|
|
|
259 |
|
|
|
260 |
<li data-description="Creating left navigation using the MenuNav Node Plugin."> |
|
|
261 |
<a href="menunav-leftnav.html">Basic Left Nav</a> |
|
|
262 |
</li> |
|
|
263 |
|
|
|
264 |
|
|
|
265 |
|
|
|
266 |
<li data-description="Creating top navigation using the MenuNav Node Plugin"> |
|
|
267 |
<a href="node-menunav-2.html">Basic Top Nav</a> |
|
|
268 |
</li> |
|
|
269 |
|
|
|
270 |
|
|
|
271 |
|
|
|
272 |
<li data-description="Creating menu button navigation using the MenuNav Node Plugin"> |
|
|
273 |
<a href="node-menunav-3.html">Menu Button Top Nav</a> |
|
|
274 |
</li> |
|
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
|
278 |
<li data-description="Creating split button navigation using the MenuNav Node Plugin"> |
|
|
279 |
<a href="node-menunav-4.html">Split Button Top Nav</a> |
|
|
280 |
</li> |
|
|
281 |
|
|
|
282 |
|
|
|
283 |
|
|
|
284 |
<li data-description="Adding shadows to submenus of a left nav using the MenuNav Node Plugin"> |
|
|
285 |
<a href="node-menunav-5.html">Left Nav with Submenus with Shadows</a> |
|
|
286 |
</li> |
|
|
287 |
|
|
|
288 |
|
|
|
289 |
|
|
|
290 |
<li data-description="Adding rounded corners to submenus of a left nav using the MenuNav Node Plugin"> |
|
|
291 |
<a href="node-menunav-6.html">Left Nav With Submenus With Rounded Corners</a> |
|
|
292 |
</li> |
|
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
|
296 |
<li data-description="Skining a menu built using the MenuNav Node Plugin to look like the menus on Flickr"> |
|
|
297 |
<a href="node-menunav-7.html">Skinning Menus Created Using the MenuNav Node Plugin</a> |
|
|
298 |
</li> |
|
|
299 |
|
|
|
300 |
|
|
|
301 |
</ul> |
|
|
302 |
</div> |
|
|
303 |
</div> |
|
|
304 |
|
|
|
305 |
|
|
|
306 |
|
|
|
307 |
</div> |
|
|
308 |
</div> |
|
|
309 |
</div> |
|
|
310 |
</div> |
|
|
311 |
|
|
|
312 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
313 |
<script>prettyPrint();</script> |
|
|
314 |
|
|
|
315 |
<script> |
|
|
316 |
YUI.Env.Tests = { |
|
|
317 |
examples: [], |
|
|
318 |
project: '../assets', |
|
|
319 |
assets: '../assets/node-menunav', |
|
|
320 |
name: 'node-menunav-6', |
|
|
321 |
title: 'Left Nav With Submenus With Rounded Corners', |
|
|
322 |
newWindow: 'true', |
|
|
323 |
auto: false |
|
|
324 |
}; |
|
|
325 |
YUI.Env.Tests.examples.push('menunav-leftnav'); |
|
|
326 |
YUI.Env.Tests.examples.push('node-menunav-2'); |
|
|
327 |
YUI.Env.Tests.examples.push('node-menunav-3'); |
|
|
328 |
YUI.Env.Tests.examples.push('node-menunav-4'); |
|
|
329 |
YUI.Env.Tests.examples.push('node-menunav-5'); |
|
|
330 |
YUI.Env.Tests.examples.push('node-menunav-6'); |
|
|
331 |
YUI.Env.Tests.examples.push('node-menunav-7'); |
|
|
332 |
|
|
|
333 |
</script> |
|
|
334 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
335 |
|
|
|
336 |
|
|
|
337 |
|
|
|
338 |
</body> |
|
|
339 |
</html> |