Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > relative positiong question

relative positiong question
Thread Tools
Fresh-Faced Recruit
Join Date: Nov 2003
Status: Offline
Reply With Quote
Aug 24, 2004, 01:01 PM
 
Hello,
I am having trouble having 2 div panes side by side. Here's my setup
<div class="header">
//with my header img as background at the top
<div class="main">
//where my main content goes at bottom of the header
<div class="side"> /* Problem -> Want this to be on right side of main*/

I Also want all these divs to be in the middle of screen. How should i set up the positioning of these divs so i can have them all centered in screen and biggest problem, have "side" div be on right hand side of "main"

Thanks for any tips.

P.S. I don't want to use absolute positioning because it screws up in mozilla but looks fine on ie.
(Last edited by hurric00; Aug 25, 2004 at 08:32 PM. )
     
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Aug 24, 2004, 01:34 PM
 
Originally posted by hurric00:
Hello,
I am having trouble having 2 div panes side by side. Here's my setup
<div class="header">
//with my header img as background at the top
<div class="main">
//where my main content goes at bottom of the header
<div class="side"> /* Problem -> Want this to be on right side of main*/

I Also want all these divs to be in the middle of screen. How should i set up the positioning of these divs so i can have them all centered in screen and biggest problem, have "side" div be on right hand side of "main"

Thanks for any tips.

P.S. I don't want to use absolute positioning because it screws up in mozilla but looks fine on ie.
Well that was rather vague, and it all depends on the specifics of your layout... whether layout is fixed or liquid, whether each pane has a fixed size... whether you have borders... if you want them to touch... if you want each column to span the full height of the main box... if there is a main box etc... But if I were doing a similar layout I'd probably approach it like so:

Code:
<div id="site"> <div id="side">side content goges here</div> <div id="main">here is your main content.</div> <div class="clear"></div> </div>
Code:
#site { width: 500px; margin: 0 auto; background: red } #side { width: 100px; background: yellow; float: right } #main { margin-right: 110px; background: orange } .clear { clear: both }
This is a very simple layout and may or may not work, depending on all the things I listed above.

Edit: I probably should of checked the code before posting it, I stupidly named both the container div and content div "main". I slightly updated it... it should work now.
(Last edited by Synotic; Aug 24, 2004 at 01:42 PM. )
     
Fresh-Faced Recruit
Join Date: Nov 2003
Status: Offline
Reply With Quote
Aug 24, 2004, 02:36 PM
 
Hi,

Thanks for the reply. That's exactly what i wanted (despite my vague explanation).
I'm gonna read some more docs to understand it fully. I not sure what .clear does yet and why you have a margin-right in #main. I had it set up all wrong i guess
     
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Aug 24, 2004, 03:47 PM
 
Originally posted by hurric00:
Hi,

Thanks for the reply. That's exactly what i wanted (despite my vague explanation).
I'm gonna read some more docs to understand it fully. I not sure what .clear does yet and why you have a margin-right in #main. I had it set up all wrong i guess
When an object is floated, it's taken out of the "flow" of its container. In this case, #side is being taken out of the flow of all the other objects in #site. If you try that site and remove the margin of #content and the background of #side, you will notice that the contents will actually go under the side. It's completely ignoring the column because, since it's floated, it's taken out of the flow. Also, if the column is longer than the main content, then it will actually spill right out of the container... again it is being ignored and the height of the container isn't affected but the floated object. Keeping all that in mind, I can now (assuming you understood it ) explain the margin and the clearer div.

When I said that the floated div was completely ignored, that was slightly misleading... in terms of actual layout, it's correct, however, you'll notice that the text of the content div is affected by the floated div. I don't know exactly why this is or if there should be perhaps an option to allow it to affect the text or not... but again, it's something that should be kept in mind. The problem is that although the text isn't underneath the right column, it's still right next to it... there's no breathing room. To fully understand the purpose of the margin, make sure that the "#side"'s background is turned off. Now with the main content, change its right margin to 50px, check. Notice how it doesn't really change anything except the red? Once you reach 100px, you're exactly the same place you were before.. assuming you don't want background colors in the final design. Now once you add 110px, you are 10 pixels away from the column, thus giving it some space. Does that make sense?

Now about the clearer... like I mentioned above, the floated div (or any floated item) doesn't affect the vertical height of its container. To solve this, you could simply make sure that the side columns are never longer than the content... but of course this is a half-assed solution and something that you can't really control. To test this, remove the clearer div, and make the column longer (2 or more lines longer) than the content. You'll see that it spills out of the main wrapper div. Add another div, with one line of text. Notice that it goes straight underneath the content div, and it too ignores the floated items. Luckily, there is a property that defines whether an object should allow an object to be floated to its left, right, or both sides. To not allow an object to be floated to an object's side is called "clearing a float". Thus, if you give your newly added div, the "clear" class, you'll notice that it appears below the floated divs, since they aren't allowed to be to the left or right of it. Now remove the text from inside your new div and you can see how the clearer div works. Hopefully

Excuse the rather longwinded explanation, but for me it's usually a lot easier to understand something if you actually know how and why it works. I could of simply said that it prevents the column from spilling out of the main div, but I don't think that would of been as helpful. If that still doesn't make any sense, feel free to ask any questions

If you're more familiar with the technique of floating images within a paragraph... either with the float property or 'align="left"' and 'align="right"', then this article might make things a bit clearer.
     
Fresh-Faced Recruit
Join Date: Nov 2003
Status: Offline
Reply With Quote
Aug 25, 2004, 08:31 PM
 
thanks for the reply...i finally got it to work and validated it

New quesion i have is how to make "drop-down" menues or these menus that expand from left to right?
e.g. http://www.pentaxcanada.ca/index_camera.php

like menus on the top

any links to any tutorials will be appreciated...
     
   
Thread Tools
Forum Links
Forum 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 On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:10 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2