How to fix Absolute Positioning In IE8?
Asked Answered
L

6

24

In every browser I've used, except ie8, an absolutely positioned element can be positioned according to the closest parent with relative positioning.

The below code shows two divs inside a table. The top div has position: relative, however, the nested, absolutely positioned element does not respect its boundaries (in ie8, it gets positioned at the bottom of the page instead of the bottom of the parent div).

Does anybody know a fix for this?

<style>
#top {
position: relative;
background-color: #ccc;
}
#position_me {
background-color: green;
position: absolute;
bottom: 0;
}
#bottom {
background-color: blue;
height: 100px;
}
</style>
<table>
  <tr>
    <td><div id="top"> Div with id="top"
        <div id="position_me"> Div with id="position me" </div>
      </div>
      <div id="bottom"> Div with id="bottom"
        <p>Lorem ipsum dolor sit amet.</p>
      </div></td>
  </tr>
</table>
Lassa answered 1/9, 2009 at 1:15 Comment(0)
S
24

Declare a doctype. I'd encourage you to use the HTML5 doctype:

<!DOCTYPE html>
Stygian answered 1/9, 2009 at 1:20 Comment(0)
W
19

Add this:

#top {
//height: 100%;
}
#position_me {
//left: 0;
}

It forces IE8 to compute position correctly in quirks mode. There are many ways to get it:

//zoom: 1;
//writing-mode: tb-rl;

See http://haslayout.net/haslayout

Woolf answered 28/1, 2010 at 16:12 Comment(0)
T
13

That's becuase you're not using the document type. And IE working in the "quircks" mode.

Try this doctype:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Tehuantepec answered 1/9, 2009 at 1:27 Comment(0)
E
6

i´d always use the HTML5 doctype, but in my case the only problem was that the parent element needed "position:relative;" specifically set. after that, it worked perfectly fine.

Expense answered 24/4, 2013 at 14:48 Comment(0)
I
2

You can also use

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

This fixed my problem!

Italicize answered 11/12, 2011 at 21:53 Comment(0)
A
0

Microsoft Says :

In most cases, we recommend that websites use the HTML5 document type to support the widest variety of established and emerging standards, as well as the broadest range of web browsers. This example shows how to specify the HTML5 document type.

For more Info

Anselmo answered 13/3, 2018 at 11:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.