Solved

Align absolute div the same in Firefox and IE

Posted on 2006-06-29
1
939 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Login area of a page 4 32
How do i set padding within the sidebar? 2 26
FIx alignment of two texts 1 26
form button worked now it doesnt anymore 9 37
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
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 …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

930 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

11 Experts available now in Live!

Get 1:1 Help Now