Right Aligned Nested Div Goes Off

V

vunet

Hello,
I have a div inside of the div:

<div id='container' style='position:relative;width:500px;'>
<div id='right' style='position:absolute;width:50%;right:
0px;'>right</div>
container
</div>

with that CSS above, 'right' div is aligned to right of the page, not
container, even though it is nested. It gets fixed when I set
container to have position:absolute. What CSS properties should I be
looking at in this case?
Note: example above is not the test-case but just an explanation.
'container' is nested within other HTML tags in real code.

Thank you for ideas.
 
J

Jeff

vunet said:
Hello,
I have a div inside of the div:

<div id='container' style='position:relative;width:500px;'>
<div id='right' style='position:absolute;width:50%;right:
0px;'>right</div>
container
</div>

with that CSS above, 'right' div is aligned to right of the page, not
container, even though it is nested.


Absolute is always absolute to the page. Relative is to it's normal
place in the document flow. You probably want to look at float: right,
and then you may wish to float your other div.

Jeff



It gets fixed when I set
 
B

Bergamot

vunet said:
'right' div is aligned to right of the page, not
container, even though it is nested. It gets fixed when I set
container to have position:absolute.

Your code snippet is not telling the whole story. Post a URL.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Aligned to the left 3
Clickable Div Block 1
Trouble with css 4
Positioning CSS components 1
Set value after clicking in field 11
Help with my responsive home page 2
Help with code 0
Justify-content not working 1

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top