Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

CSS Forum


You are currently viewing our CSS Forum as a guest. Please register to participate.
Login



Reply
is this the best way to position a div anywhere inside a wrapper div?
Old 12-03-2008, 08:14 AM is this the best way to position a div anywhere inside a wrapper div?
Webmaster Talker

Posts: 611
Trades: 0
is this the best way to position a div anywhere inside a wrapper div?

here is the css for the div. i put it inside a wrapper div. i wanted it positioned anywhere i want it and was wondering if this is the proper way. any help greatly appreciated. derek.
here is the code.

Code:
#randomrectangle {
  margin-top: 200px;
  margin-left: 200px;
  width: 120px;
  height: 100px;
  background-color: pink;
  }
silverglade is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-03-2008, 08:39 AM Re: is this the best way to position a div anywhere inside a wrapper div?
Webmaster Talker

Posts: 611
Trades: 0
now im trying to place one div box on top of the other but i it seems like the second box is relating its position to the top box instead of the top corner of the wrapper div. please help. derek. any help appreciated. how would i position the box in relation to the top left corner of the wrapper div? here is the code.

Code:
#randomrectangle {
  margin-top: 200px;
  margin-left: 200px;
  width: 120px;
  height: 100px;
  background-color: pink;
  }
  #underrandom {
  margin-top: 0px;
  margin-left: 200px;
  width: 120px;
  height: 100px;
  background-color: red;
  }

Last edited by silverglade; 12-03-2008 at 08:42 AM..
silverglade is offline
Reply With Quote
View Public Profile
 
Old 12-03-2008, 08:53 AM Re: is this the best way to position a div anywhere inside a wrapper div?
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
Adding a position: absolute; to the CSS for an element will allow you to place the element relative to it's container by specifying top/left/bottom/right in the CSS as well.

Examples to be found here:
http://www.w3schools.com/Css/pr_class_position.asp
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 12-03-2008, 09:39 AM Re: is this the best way to position a div anywhere inside a wrapper div?
Webmaster Talker

Posts: 611
Trades: 0
thank you, also when i do the following style to my div, in the browser, the div box goes outside of my container div. i dont understand why. any help appreciated. thanks. derek

here is the new code.

Code:
#absolutebox {
  position: absolute;
 
  left: 200px;
  top: 300px;
  width: 100px;
  height: 100px;
  background-color: blue;
  }
the following divs stay inside the div box, but are only positioned relative to the divs above it.

Code:
#randomrectangle {
  margin-top: 200px;
  margin-left: 200px;
  width: 120px;
  height: 100px;
  background-color: pink;
  }
  #underrandom {
  margin-top: 0px;
  margin-left: 200px;
  width: 120px;
  height: 100px;
  background-color: red;
  }

Last edited by silverglade; 12-03-2008 at 10:05 AM..
silverglade is offline
Reply With Quote
View Public Profile
 
Old 12-03-2008, 11:01 AM Re: is this the best way to position a div anywhere inside a wrapper div?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
What you're seeing in the first example I believe, is margin collapse on the left-side(link to all the code?), which is the correct behavior, but often confusing in situations like this. Adding 1px of padding or a 1px border to the parent will stop it from happening.

As far as absolute positioning goes, the parent must have position: relative, or else the absolutely positioned element will be positioned relative to the nearest ancestor that has relative positioning, until it reaches the <body>.
__________________
Join me on
Please login or register to view this content. Registration is FREE

Last edited by wayfarer07; 12-03-2008 at 11:03 AM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 12-03-2008, 03:16 PM Re: is this the best way to position a div anywhere inside a wrapper div?
Webmaster Talker

Posts: 611
Trades: 0
awesome it worked thank you very much. it wouldnt let me give you talkupation though for some reason. sorry. derek but thank you.
silverglade is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to is this the best way to position a div anywhere inside a wrapper div?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30470 seconds with 12 queries