Solved

Align absolute div the same in Firefox and IE

Posted on 2006-06-29
1
938 Views
Last Modified: 2008-02-01
Hi
I have a vertical menu on my site (i.e. top to bottom) that uses table rows for each menu element.
When a user mouses over each menu item, I have a submenu appear as a DIV (initially this div is hidden).
To stop the submenu div breaking the page flow, I made it absolute, so it floats over everything. But because my site is centred, I never know the exact position of the menu, so I have used the trick of putting the absolute div inside a relative div:

<tr>
<td width="158" height="24" align="center" onmouseover="javascript:document.getElementById('submenu1').style.display = 'block';" onmouseout="javascript:document.getElementById('submenu1').style.display = 'none';" valign="middle">
<div style="position: relative;">
<a href="http://foo">Main menu link</a>
<div id="submenu1" style="display: none; position: absolute; top: 0px; left: 140px;">Submenu HTML here</div>
</div>
</td>
</tr>

This works fine except the submenu div is positioned differently in IE and Firefox...

Is there a way to do this that will make the submenu div appear in the same place in both IE and Firefox? I am pregenerating the menu html and saving it in a database, otherwise I could have done a browser detect and changed the top amd left attributes of the absolute div for each browser.

cheers
0
Comment
Question by:pr0fess0r
1 Comment
 
LVL 12

Accepted Solution

by:
GoofyDawg earned 250 total points
ID: 17032654
You could use the !important directive to make FF and other compliant browsers work:

display: none; position: absolute; top:4px!important;top: 0px; left:150px!important;left: 140px;

IE ignores any CSS attributes that have an !important attached, while FF and other more compliant browsers will obey the directive and use those values. There is one caveat... IE7 (beta) will obey the important directive, but it still renders like IE 6, which sucks... Hopefully they'll have that fixed by the time it goes gold.

GoofyDawg
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now