Position absolute div obeying body margin

2 replies
I have a position absolute div in the body of an html file. I want it to obey the body-margins. Please find my code at jsfiddle.net/vHApr . Please help me.! It is urgent.
#absolute #body #div #margin #obeying #position
  • Profile picture of the author Michael71
    What you want is not possible. You should read and understand position: absolute...

    When you set right:0; it means 0px
    Signature

    HTML/CSS/jQuery/ZURB Foundation/Twitter Bootstrap/Wordpress/Frontend Performance Optimizing
    ---
    Need HTML/CSS help? Skype: microcosmic - Test Your Responsive Design - InternetCookies.eu

    {{ DiscussionBoard.errors[7949676].message }}
  • Profile picture of the author ttkim
    Well, first, i don't know why your body has two margins. Take out the first one because it's pointless.

    You can achieve what you want using several methods.

    Your body's margin is 50 pixels. Then, just set

    Code:
    right: 50px;
    Not sure why you didn't just do that. If you don't want to do that, then you can set a parent div with a relative positioning.

    Code:
    <body>
        <div class="parent-div">
            <div class="test">
            </div>
        </div>
    </body>
    Code:
    .parent-div{position:relative;}
    Keep the rest of your code the same, and it'll work.
    {{ DiscussionBoard.errors[7949855].message }}

Trending Topics