Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Align absolute div the same in Firefox and IE

Posted on 2006-06-29
1
941 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 Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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…

809 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