Solve the Problem of covering Div by dropdownlist

Source: Internet
Author: User
Problem

When you use a div to display some help information on the top of some controls, you may encounter the problem that the control overwrites the help information of the div. This problem occurs because the Z-index attribute is not set for the control on the page, and the Z-index attribute determines the front and back layers of the element display, an element with a large Z-index value is always in front of an element with a smaller Z-index value.

Dropdownlist does not have the Z-index attribute. They are window-level controls. If you want to display a div on the dropdownlist control, you will encounter the dropdownlist to overwrite the div. The following figure shows a common problem in IE 6.

Solution

Assume that you want to display a div when you move the cursor over an image on An ASPX page. And you can use JavaScript to achieve this effect.CodeIn, you will control the position of the DIV display. If a combo box's list box is in this position, the user will see that these controls block the DIV content.

There are many solutions to this problem. I use the simplest one. This solution is to display an IFRAME of the same size as the DIV in the place where the DIV is displayed.

You can easily control the size of this IFRAME, because the height and width of the DIV are known.

Code

Put an IFRAME at the top of the page:

<IFRAME Width="0" Scrolling="No" Height="0" 
Frameborder="0" Class="Iballoonstyle" ID="Iframetop"></IFRAME>
 
 

Use JavaScript to display the IFRAME at the same time where you want to display the DIV:

VaRLayer =Document. Getelementbyid (divtip. ID );
Layer. style. Display = 'block ';
VaRIFRAME =Document. Getelementbyid ('iframetop ');
IFRAME. style. Display = 'block ';
IFRAME. style. width = Layer. offsetWidth-5;
IFRAME. style. Height = Layer. offsetHeight-5;
IFRAME. style. Left = Layer. offsetleft;
IFRAME. style.Top= Layer. offsettop;
 
 

In the preceding JavaScript code, divtip. ID is the ID value of the DIV to be displayed.

Address: http://www.codeproject.com/KB/dotnet/Overlapping.aspx

 

Reference:

Http://topic.csdn.net/t/20050909/11/4259391.html

Http://www.cnblogs.com/zhc088/archive/2007/08/22/864981.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.