Skip to content

Commit b190711

Browse files
committed
Documented ui-front and stacking elements. Fixes jquery#142.
1 parent 99b979b commit b190711

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

pages/theming/css-framework.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h3>Layout Helpers</h3>
2323
<code>.ui-helper-clearfix</code>: Applies float wrapping properties to parent elements.
2424
</li>
2525
<li>
26-
<code>.ui-front</code>: Applies z-index to manage the stacking of multiple widgets on the screen.
26+
<code>.ui-front</code>: Applies z-index to manage the stacking of multiple widgets on the screen. See the page about <a href="/theming/stacking-elements/">stacking elements</a> for more details.
2727
</li>
2828
</ul>
2929

pages/theming/stacking-elements.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<script>{
2+
"title": "Stacking Elements",
3+
"termSlugs": {
4+
"category": [ "theming" ]
5+
}
6+
}</script>
7+
8+
Widgets that stack, or move in front of other elements, often present challenges
9+
when placed into real world pages. It's usually easy to either change the `z-index`
10+
or parent of the stacked element to avoid any collisions on the page. However,
11+
jQuery UI needs a generic solution that doesn't require manually playing with
12+
`z-index` values. This is accomplished via the `ui-front` class, and usually an
13+
accompanying `appendTo` option on stacking widgets.
14+
15+
16+
17+
## The `ui-front` class
18+
19+
The `ui-front` class is very basic. It just sets a static `z-index` value on the
20+
element. However, the existence of the class is used to indicate where stacking
21+
elements should be appended. This allows us to take advantage of nested stacking
22+
contexts, resulting in a default DOM position that works for most use cases.
23+
24+
*Note: When using `ui-front`, you must also set `position` to `relative`,
25+
`absolute` or `fixed` in order for the `z-index` to be applied.*
26+
27+
28+
29+
## The stacking technique
30+
31+
Any widget that appends a stacking element to the page must use the `ui-front`
32+
class, and in many cases should have an `appendTo` option. The following logic
33+
should be applied to the stacking element:
34+
35+
* If a value is provided for the `appendTo` option, then append the stacking
36+
element to the specified element.
37+
* If the `appendTo` option is set to `null` (default), then the widget should
38+
walk up the DOM from the associated element. For example, when the autocomplete
39+
menu is appended to the DOM, the walking starts from the associated input element.
40+
* If an element with the `ui-front` class is found, append to that element.
41+
* If no element with the `ui-front` class is found, append to the body.
42+
* The stacking element must also have `position` set to `relative`, `absolute`,
43+
or `fixed` in order for the `z-index` from the `ui-front` class to be applied.
44+
Using [.position()](/position/) will automatically set `position`.

0 commit comments

Comments
 (0)