Article ID: 177378 - Last Review: May 11, 2006 - Revision: 3.0 INFO: How the Z-index Attribute Works for HTML ElementsThis article was previously published under Q177378 On This PageSUMMARY
There are many ways to classify elements on a Web page. For the purposes of this article and the z-index attribute, we can divide them into two categories: windowed and windowless. Windowed Elements
Windowless Elements
MORE INFORMATION
All windowed elements paint themselves on top of all windowless elements, despite the wishes of their container. However, windowed elements do follow the z-index attribute with respect to each other, just as windowless elements follow the z-index attribute with respect to each other. All windowless elements are rendered on the same MSHTML plane, and windowed elements draw on a separate MSHTML plane. You can use z-index to manipulate elements on the same plane but not to mix and match with elements in different planes. You can rearrange the z-indexing of the elements on each plane, but the windowed plane always draws on the top of the windowless plane. How Z-index Works in Internet Explorer 5In Internet Explorer 5, IFRAMEs are windowed controls and follow the z-index attribute with respect to other windowed controls such as SELECT elements. If the z-index of IFRAME is greater than the SELECT elements, the IFRAME draws on top of the SELECT elements and vice versa. If the z-index is the same, the order of the elements on the page takes precedence; therefore, the last element draws on top of the previous element.The following sample code illustrates this: When you set the z-index of the SELECT element to 5, the IFRAME draws on top of the SELECT element because the IFRAME is the last element and, therefore, it takes precedence over SELECT. If the SELECT element followed the IFRAME, the element draws on top of the IFRAME when the z-indexes are same. How Z-index Works in Internet Explorer 5.5Z-indexing is taken to a completely new level in Internet Explorer 5.5 in which IFRAMEs are no longer windowed elements. For more information, see the "Windowless IFRAME Elements" topic in the following Microsoft Developer Network (MSDN) article:http://msdn.microsoft.com/workshop/author/dhtml/overview/compat.asp#WindowlessFrames
(http://msdn.microsoft.com/workshop/author/dhtml/overview/compat.asp#WindowlessFrames)
This leaves the SELECT element as the only element that is windowed. If you use the preceding code to run the page in Internet Explorer 5.5, when you set the z-index of the SELECT element to a value that is greater than 5, it draws on top of the IFRAME. When you set the z-index of the SELECT element to a value that is less than 5, the IFRAME overlaps it, even though they are both windowless elements. This is what makes the IFRAME unique: it follows z-index with respect to windowless elements, and it supports z-index with respect to windowed elements like the SELECT element in this case.When you set the z-index of the DIV element to a value that is greater than the IFRAME (such as 6), the DIV covers the IFRAME. This supports the above statement that IFRAMEs are windowless and that they follow z-order with respect to other windowless elements. When you set the z-index to a value that is less than or equal to the IFRAME (such as 5), it still draws on top of the DIV because the order of the elements takes precedence. When you set the z-index of the DIV to 6 and leave the z-index of the SELECT element and IFRAME at 5, the SELECT element always draws on top of the DIV because it is windowed. However, IFRAME tries to draw on top of SELECT because it is last in the order. To prevent this, the value of the SELECT element's z-index must be greater than that of the IFRAME, or the SELECT element must be last in the list to ensure that the element always draws on top of the IFRAME when the z-indexes are the same. Because of this, z-indexing similar content can be difficult. To work around this, use the following methods:
REFERENCESFor more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites: http://msdn.microsoft.com/ie/
(http://msdn.microsoft.com/ie/)
http://support.microsoft.com/iep (http://support.microsoft.com/iep) APPLIES TO
| Article Translations
|


Back to the top
