Reply
Should I use a div or table for this?
Old 09-16-2007, 08:36 PM Should I use a div or table for this?
Nathand's Avatar
Extreme Talker

Posts: 210
Location: USA
I need to split up the pages content into two differently sized parts, they'll be centered in the middle of the page.

Right now I have a div that is centered, and then I have a table with two columns to split up the content inside the div. Would it be better to have two divs inside the centered div, or to have a table with two columns inside the centered div?
Nathand is offline
Reply With Quote
View Public Profile Visit Nathand's homepage!
 
When You Register, These Ads Go Away!
Old 09-16-2007, 09:03 PM Re: Should I use a div or table for this?
joder's Avatar
Flipotron

Posts: 6,443
Name: James
Location: In the ocean.
div's, since div's are for layout and tables for tabular data.
joder is offline
Reply With Quote
View Public Profile
 
Old 09-16-2007, 09:51 PM Re: Should I use a div or table for this?
Nathand's Avatar
Extreme Talker

Posts: 210
Location: USA
Ok, so how to I align the divs side by side? When I change them from table cells to divs instead of aligning side by side one drops vertically below the other?
Nathand is offline
Reply With Quote
View Public Profile Visit Nathand's homepage!
 
Old 09-16-2007, 11:18 PM Re: Should I use a div or table for this?
coolkbk585's Avatar
Be good this Christmas!

Latest Blog Post:
KBlog has been deativated
Posts: 642
Name: Kyle
Location: Ada, MI
Well, first of all, make sure that the divs that you are making are not too wide for the are that you are putting them in.

If they aren't, then you need to float them to make them next to each other. This is because divs are a block-level element.

http://www.w3schools.com/css/pr_class_float.asp < Read up on floats.
__________________
<?php if($Adsense_Revenue > 0): define('HAPPINES','100%'); else: define('HAPPINESS', '0%') endif; ?>
coolkbk585 is offline
Reply With Quote
View Public Profile Visit coolkbk585's homepage!
 
Old 09-17-2007, 12:23 AM Re: Should I use a div or table for this?
joder's Avatar
Flipotron

Posts: 6,443
Name: James
Location: In the ocean.
Here are some templates and info that will help
http://www.intensivstation.ch/en/templates/
http://css-discuss.incutio.com/?page=FloatLayouts
http://www.alistapart.com/articles/multicolumnlayouts
joder is offline
Reply With Quote
View Public Profile
 
Old 09-17-2007, 12:20 PM Re: Should I use a div or table for this?
Nathand's Avatar
Extreme Talker

Posts: 210
Location: USA
I cannot get this working with div's. Could someone post some sample code that has two div's aligned side-by-side inside a container div that has a border around it?

I really have been trying, I just can't figure out anything that will work in both ie and ff.

Thanks for the help,
Nathan
Nathand is offline
Reply With Quote
View Public Profile Visit Nathand's homepage!
 
Old 09-17-2007, 01:24 PM Re: Should I use a div or table for this?
joder's Avatar
Flipotron

Posts: 6,443
Name: James
Location: In the ocean.
This is the basic outline:

HTML Code:
#container{
}

#left {
}

#right {
    float:right;
}
I left the container and left with nothing in them just to show them here. You can add what you need.

In the html page

HTML Code:
<div id="container">

    <div id="left">
       Content of left div
    </div>

    <div id="right">
        Content of right div
    </div>

</div>
joder is offline
Reply With Quote
View Public Profile
 
Old 09-17-2007, 01:33 PM Re: Should I use a div or table for this?
Nathand's Avatar
Extreme Talker

Posts: 210
Location: USA
That doesn't work Joder. If you add a background color to the left and right divs you will see that they are not side by side, they get stacked up on eachother vertically, which is what I'm trying to avoid...
Nathand is offline
Reply With Quote
View Public Profile Visit Nathand's homepage!
 
Old 09-17-2007, 01:44 PM Re: Should I use a div or table for this?
joder's Avatar
Flipotron

Posts: 6,443
Name: James
Location: In the ocean.
Here how I do it, maybe someone else has a better way. On one div (left or right) I add a width
Example:
width: 15em
On the other div I add a margin. Let's assume you added a width to the right div, then on the left
margin-right: 18em;

The margin is larger because it doensn't line up right making it the same as the width of the div.

You may have to play with the numbers and look in different browsers.
joder is offline
Reply With Quote
View Public Profile
 
Old 09-17-2007, 03:18 PM Re: Should I use a div or table for this?
LadynRed's Avatar
Super Moderator

Posts: 6,743
Location: Tennessee
If you float the div you MUST give it a width.
Things to consider -
How wide is your container ?
How wide is your left div including margins, padding and borders ?
How wide is your right div including margins, padding and borders ?

Does the drop occur only in IE or is it happing in Firefox or Opera ?
IE has MANY bugs related to floats because of its broken box model, you may have run into one (or more) of them.

The total width of the right and left, with margins and padding and borders, must NOT be wider than the container width.
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!
"Using or working with IE is like having to wear a 1970's polyester suit with pantyhose and a girdle, to work everyday"
Carolina Corvette Club
LadynRed is offline
Reply With Quote
View Public Profile
 
Old 09-17-2007, 05:05 PM Re: Should I use a div or table for this?
Nathand's Avatar
Extreme Talker

Posts: 210
Location: USA
Ok. Here's the code I'm having the most success with:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head><title></title>

<style type="text/css">

body {
margin: 0 0 0 0;
}

div.divcontainerbody {
margin-right:auto;
margin-left:auto;
width:750px;

background-color: red;
padding: 0 0 0 0;
border-left: 1px solid black;
border-right: 1px solid black;
border-bottom: 1px solid black;
border-top: 1px solid black;
position: relative;
}

div.divmainbody{
background-color: blue;
height: 200px;
width: 575px;
float:left;
display: table;
}

div.divleftmenu{
background-color: green;
height: 200px;
width: 175px;
float: left;
display: table;
}

</style>
</head>
<body>

<br><br><br><br> <!-- This just to moves it down a little for testing -->
<div class="divcontainerbody"> <!-- Create a container Div -->

<div class="divleftmenu">
I am the left div, "divleftmenu"
</div>

<div class="divmainbody">
I am the right div, "divmainbody"
</div>

</div> <!-- End of container Div -->

</body>
</html>
This works in ie, however in firefox something weird happens. It's kind of hard to describe this (it would be easier to just copy/paste the code and try for yourself), but the borders of the containing div kind of scrunch up and it appears that the two other divs are outside of the container div...
Nathand is offline
Reply With Quote
View Public Profile Visit Nathand's homepage!
 
Old 09-17-2007, 05:47 PM Re: Should I use a div or table for this?
Nathand's Avatar
Extreme Talker

Posts: 210
Location: USA
One thing I forgot to add, is that with the above code, if I change "position: relative;" to "position: absolute;" in "div.divcontainerbody" then the problems go away. But then all the divs are aligned to the left side of the page.
Nathand is offline
Reply With Quote
View Public Profile Visit Nathand's homepage!
 
Old 09-18-2007, 01:34 AM Re: Should I use a div or table for this?
joder's Avatar
Flipotron

Posts: 6,443
Name: James
Location: In the ocean.
HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head><title></title>

<style type="text/css">

body {
    margin: 0;
    }

div.divcontainerbody {
    margin: 5em auto;
    width:750px;
    background-color: red;
    padding: 0;
    border: 5px solid black;
    height: 200px;
    }

div.divmainbody{
    background-color: blue;
    width: 575px;
    float:right;
    height: 200px;
    position: relative;
    }

div.divleftmenu{
    background-color: green;
    width: 175px;
    float: left;
    height: 200px;
    position: relative;
    }

</style>
</head>
<body>

<div class="divcontainerbody"> <!-- Create a container Div -->

<div class="divleftmenu">
I am the left div, "divleftmenu"
</div>

<div class="divmainbody">
I am the right div, "divmainbody"
</div>

</div> <!-- End of container Div -->

</body>
</html>
joder is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Should I use a div or table for this?
 

Thread Tools

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

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


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


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

 


Page generated in 0.17429 seconds with 12 queries