Simulating position: fixed in IE6 with a div of 10

2020-08-03 13:52发布

问题:

I have a sidebar on my webpage that is supposed to span 100% of the page (vertically). It is then supposed to stay there, so when the rest of the content scrolls it does not. To do this, I used:

body
{
    height: 100%;
}

#sidebar
{
    height: 100%;
    width: 120px;
    position: fixed;
    top: 0;
    left: 0;
}

This works great in all modern browsers! Unfortunately, I have to code for IE6, which does not support position: fixed. Do you have any idea how I would do this?

回答1:

This is the fix »

Me? I'd just as soon use a more common navigation method, or use (gasp) frames.



回答2:

As stated here

  1. First, put IE6 into "standards mode" by using a strict DOCTYPE. Note that IE6's standards mode is known for its extremely odd quirks. We are taking advantage of one now.
  2. Use IE conditional comments to style the HTML and BODY tags like so:

    html, body {height:100%; overflow:auto;}

  3. Style anything you want to stay fixed as position:absolute.