I have a div inside another div that has borders on the right and left to center it:
I want to change the inner div to absolute so that the outer div flows up behind it:
Now it’s not centered. Is there any way to fix that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have two problems here:
top,bottom,left, orright, so it’s being left in its original position. Which would be fine, except…width,height) are a percentage of their context parent‘s outer dimensions (in this case, the<body>element).You can re-center the inner div by setting
left: 0;on it, but it will still overlap the body’s borders. To fix that as well, the simplest method is probably to drop thewidthproperty in favor of setting bothleftandrightto the width of the body’s borders. (This acts as a kind of “smart stretching” for absolutely-positioned elements.)