?
Solved

Align absolute div the same in Firefox and IE

Posted on 2006-06-29
1
Medium Priority
?
945 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
[X]
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
1 Comment
 
LVL 12

Accepted Solution

by:
GoofyDawg earned 1000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

CSS3 Custom checkboxes This article shows how to style the checkbox form element using only CSS. Works in: Chrome, FF, Safari, Opera, IE9+ Uses modernizr.js to check for :checked pseudo class, falling back to plain old checkboxes (IE8 and bel…
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 a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
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…
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

770 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