问题
I am writting some html code which have following structure
<div style="position:relative">
<form>
<table>
<tr>
<td> <div id="Upper_Element" style="position:absolute;z-index:10"></div> </td>
</tr>
<tr>
<td> <div id="Lower_Element" style="position:absolute;z-index:-1"></div> </td>
</tr>
</table>
</form>
</div>
here Upper_Element is a YUI autocomplete text box (where suggestion are displayed when user enters anything like google) and Lower_Element is normal drop down box(<select>
).
In IE6 , When autocomplete suggestion are displayed Lower_Element is displayed over the suggestions list .
In other browser like IE8 its working fine.
I tried position and z-index attributes but no luck.
Please let me know what else can be tried.
Thanks in advance !
回答1:
What do you mean by "Lower_Element is a normal drop down box"? Is it a <select>
element or a <div>
as in your example? If it is a <select>
then you are seeing a very old bug that affects IE6 and has been asked/solved many times before, for example Z-Index problems with IE6 and html <select> element and iframe shimming or ie6 (and below) select z-index bug
回答2:
Use position: absolute
and z-index
attribute to position one element above another
Related links:
- http://www.htmldog.com/reference/cssproperties/position/
- http://www.htmldog.com/reference/cssproperties/z-index/
Code
<div style="position:absolute"> ... </div>
Positioning:
<div style="position:absolute; top: 100px; left: 100px"> ... </div>
UPD
<div style="position:relative">
<form>
<div id="upper_element" style="position:absolute; z-index:2">I am top level div!</div>
<div id="lower_element" style="position:absolute; z-index:1">I am on the bottom of life</div>
</form>
</div>
http://jsfiddle.net/vLx6X/
来源:https://stackoverflow.com/questions/5621220/how-to-display-one-div-over-another-div-in-ie6