Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: absolute positioning in different browsers

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!

like image 1000
luqita Avatar asked May 04 '11 10:05

luqita


People also ask

When should you use absolute positioning CSS?

Absolute. Position absolute takes the document out of the document flow. This means that it no longer takes up any space like what static and relative does. When position absolute is used on an element, it is positioned absolutely with reference to the closest parent that has a position relative value.

What can I use instead of position absolute?

We can use CSS absolute positioning to overlap elements, but there's some advantages to using CSS grid instead. Let's explore using CSS grid as an alternative to position absolute.

How do you move an absolute position in CSS?

Absolute Positioning You can use two values top and left along with the position property to move an HTML element anywhere in the HTML document. Move Left - Use a negative value for left. Move Right - Use a positive value for left. Move Up - Use a negative value for top.

What type of position is positioning elements only by browser window?

Fixed positioning is really just a specialized form of absolute positioning; elements with fixed positioning are fixed relative to the viewport/browser window rather than the containing element; even if the page is scrolled, they stay in exactly the same position inside the browser window.


1 Answers

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 :)

like image 128
luqita Avatar answered Oct 04 '22 00:10

luqita