Search code examples
cssalignmentcss-float

How to align an element applying css margins that does not get modified according to browsers and screen resolutions?


I need some stuff that´s inside a specific div element, to float in a specific place. Naturally, I get different positions according to screen resolutions and browsers. I need this block of content to appear on the top right corner, but not at the very very top, but about 3 centimeters from the top.

How can I get the position fixed?

I´ve tried this:

#sidebars {
    margin: -37% 1% 0 0;
    width: 35%;
}

And it works in one page with a specific browser only (I´m using latest firefox version to test this).

So, I´ve tried a fixed position, only to get a result that does not respect the margins. So, I´ve added some float to the right, with no consequence:

#sidebars {
    float: right;
    margin: -37% 1% 0 0;
    position: fixed;
    width: 35%;
}

Any ideas? Thank you very much in advance for your insight!!

Rosamunda


Solution

  • Sounds like you do want a fixed position, but I'm pretty sure you don't need the margins. To be clear, position: fixed; will position an element with the window (whereas absolute is to the document). I'm betting you're looking for something like this:

    #sidebars {
        position: fixed;
        width: 35%;
        right:0px;
        top:0px; /* or whatever spacing you said you need from the top of the window */
    }