| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
Registered User
|
positioning question
why does float have to be used in this example. why cant you just set right and top to zero to have it sit in the top right corner of a div? <html> <head> <style> .one{width:500px; height:300px; border:1px black solid;} .two{width:100px; height:100px; border:1px red solid; position:relative; right:0px; top:0px; float:right;} </style> </head> <body> <div class=one> test1 <div class=two>test2</div> </div> </body> </html |
|
|
|
|
|
#6 (permalink) |
|
Senior Member
Join Date: Oct 2006
Posts: 2,313
|
Ok, "position:absolute" will take the element out of the normal flow of the XHTML document, and place it where you set it in the css, in relation to the nearest parent that is set as "position:relative". By default, the only element on a page that is set as "postion:relative" is the <body> tag. So if you just stick a div into the xhtml, and set the "position:absolute", it will position itself against the entire page. Now if you put your "position:absolute" element inside another div that has its "position:relative", it will position itself against that. I avoid using "position" as much as possible, wont use it unless there is another way. Can set off some nasty bugs in different resolutions/browsers. Or at least I assume there is, I was really put off by using it when I was first learning CSS. |
|
![]() |