{"id":14,"date":"2023-08-25T17:38:05","date_gmt":"2023-08-25T17:38:05","guid":{"rendered":"\/\/api.jqueryui.com\/1.10\/?page_id=14"},"modified":"2023-08-25T17:38:05","modified_gmt":"2023-08-25T17:38:05","slug":"stacking-elements","status":"publish","type":"page","link":"https:\/\/api.jqueryui.com\/1.10\/theming\/stacking-elements\/","title":{"rendered":"Stacking Elements"},"content":{"rendered":"<p>Widgets that stack, or move in front of other elements, often present challenges\nwhen placed into real world pages. It&apos;s usually easy to either change the <code>z-index<\/code>\nor parent of the stacked element to avoid any collisions on the page. However,\njQuery UI needs a generic solution that doesn&apos;t require manually playing with\n<code>z-index<\/code> values. This is accomplished via the <code>ui-front<\/code> class, and usually an\naccompanying <code>appendTo<\/code> option on stacking widgets.<\/p>\n<h2 class=\"toc-linked\"><a href=\"#the-ui-front-class\" id=\"the-ui-front-class\" class=\"icon-link toc-link\"><span class=\"visuallyhidden\">link<\/span><\/a> The <code>ui-front<\/code> class<\/h2><p>The <code>ui-front<\/code> class is very basic. It just sets a static <code>z-index<\/code> value on the\nelement. However, the existence of the class is used to indicate where stacking\nelements should be appended. This allows us to take advantage of nested stacking\ncontexts, resulting in a default DOM position that works for most use cases.<\/p>\n<p><em>Note: When using <code>ui-front<\/code>, you must also set <code>position<\/code> to <code>relative<\/code>,\n<code>absolute<\/code> or <code>fixed<\/code> in order for the <code>z-index<\/code> to be applied.<\/em><\/p>\n<h2 class=\"toc-linked\"><a href=\"#the-stacking-technique\" id=\"the-stacking-technique\" class=\"icon-link toc-link\"><span class=\"visuallyhidden\">link<\/span><\/a> The stacking technique<\/h2><p>Any widget that appends a stacking element to the page must use the <code>ui-front<\/code>\nclass, and in many cases should have an <code>appendTo<\/code> option. The following logic\nshould be applied to the stacking element:<\/p>\n<ul>\n<li>If a value is provided for the <code>appendTo<\/code> option, then append the stacking\nelement to the specified element.<\/li>\n<li>If the <code>appendTo<\/code> option is set to <code>null<\/code> (default), then the widget should\nwalk up the DOM from the associated element. For example, when the autocomplete\nmenu is appended to the DOM, the walking starts from the associated input element.<ul>\n<li>If an element with the <code>ui-front<\/code> class is found, append to that element.<\/li>\n<li>If no element with the <code>ui-front<\/code> class is found, append to the body.<\/li>\n<\/ul>\n<\/li>\n<li>The stacking element must also have <code>position<\/code> set to <code>relative<\/code>, <code>absolute<\/code>,\nor <code>fixed<\/code> in order for the <code>z-index<\/code> from the <code>ui-front<\/code> class to be applied.\nUsing <a href=\"\/1.10\/position\/\">.position()<\/a> will automatically set <code>position<\/code>.<\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>A pattern for handling z-index and stacking elements.<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":8,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-14","page","type-page","status-publish","hentry","category-theming"],"_links":{"self":[{"href":"https:\/\/api.jqueryui.com\/1.10\/wp-json\/wp\/v2\/pages\/14","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/api.jqueryui.com\/1.10\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/api.jqueryui.com\/1.10\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/api.jqueryui.com\/1.10\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/api.jqueryui.com\/1.10\/wp-json\/wp\/v2\/comments?post=14"}],"version-history":[{"count":1,"href":"https:\/\/api.jqueryui.com\/1.10\/wp-json\/wp\/v2\/pages\/14\/revisions"}],"predecessor-version":[{"id":15,"href":"https:\/\/api.jqueryui.com\/1.10\/wp-json\/wp\/v2\/pages\/14\/revisions\/15"}],"up":[{"embeddable":true,"href":"https:\/\/api.jqueryui.com\/1.10\/wp-json\/wp\/v2\/pages\/8"}],"wp:attachment":[{"href":"https:\/\/api.jqueryui.com\/1.10\/wp-json\/wp\/v2\/media?parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/api.jqueryui.com\/1.10\/wp-json\/wp\/v2\/categories?post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/api.jqueryui.com\/1.10\/wp-json\/wp\/v2\/tags?post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}