2

I have a #wrapper { margin: 0 auto } centered in the middle. I want to align a div.version inside of that wrapper at the top right corner (of this wrapper). So the .version div should still be inside of the #wrapper.

Which position value do I have to use here?

1 Answer 1

3

You can make use of absolute and relative positioning for your divs like this:

#wrapper {
 margin: 0 auto;
 position:relative;
 width:400px;
 background:green;
 clear:both;
 overflow:auto;
 height:100px;
}

.version {
  position:absolute;
  top:0;
  right:0;
  background:blue;
  height:100px;
  width:50px;
}

Check out the DEMO

So, to make an element appear inside another element, you should give parent a position set to relative while any child element a position of absolute :)

Check out the nice article written on the subject at css-tricks.com:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.