CSS: absolute positioning in different browsers

20,623

Got it to work... The parent div needs to have position:relative in it's CSS declaration. If anyone comes across this problem check your parent div :)

Share:
20,623
luqita
Author by

luqita

Updated on July 09, 2022

Comments

  • luqita
    luqita almost 2 years

    Why is this getting different positions on different browsers?

    {
        position: absolute;
        left:332px;
        top: 210px;
        width: 293px;
        height: 215px;
        border: 1px solid #000000;
        background-color: #143f72;
        -moz-border-radius: 10px;
        -ms-border-radius: 10px;
        -webkit-border-radius: 10px;
        -khtml-border-radius: 10px;
    }
    

    In IE it goes to the left like 100px compared to Firefox, and in Chrome it goes like 100px to the right relative to FF... Why?

    Edit: The html is just <div id="container"><div id="the_css_above_div"></div></div>

    #container has the following css:

    #container{
        float:left;
        width: 632px;
    }
    

    Thanks!

    • netbrain
      netbrain about 13 years
      need html code in order to get to the bottom of this.
    • anothershrubery
      anothershrubery about 13 years
      Just checked it on IE8, FF and Chrome. Doesn't seem to be any different on any of them. Check jsfiddle.net/EQn2E . Would need to see other code to see if there is a problem.
    • luqita
      luqita about 13 years
      the html is just <div id="that_css_id"></div>
    • Bazzz
      Bazzz about 13 years
      Note that position: absolute is relative to the first parent with a position other than the default. Maybe some browsers consider a float different from default and other browsers do not?
    • thirtydot
      thirtydot about 13 years
      If you really want to get to the bottom of this, make a complete test case using jsFiddle or JS Bin. Or, provide a live link to your page.
    • limitlessloop
      limitlessloop about 13 years
      Adding position: relative to the container might fix the issues you're experiencing, but that's just a wild guess. Recommend providing a link to a test page like @thirtydot and @anothershrubery suggested. :)
  • anothershrubery
    anothershrubery about 13 years
    Or provide people trying to help with more info?
  • Michael D
    Michael D about 13 years
    I believe it is true not just for IE... blocks are positioned absolutely in relationship to the parent that has position attribute set to relative or absolute, or in relationship to the window if no parent has position defined...
  • somdow
    somdow almost 12 years
    i was JUST about to post something about this....problem ive been having and as SOON as i saw your "got it to work" im like, WTF I KNOW THIS!!!! lol......thanks. +1
  • sehummel
    sehummel over 10 years
    Thanks, luqita. I would never have figured this out without your post. +1