Forum Moderators: not2easy

Message Too Old, No Replies

Floated Div problem

         

Pikin_It_Up

9:04 am on Apr 2, 2004 (gmt 0)

10+ Year Member



I am working with a two column design.

I have a container, header, footer, left container and content container.

The content container is floated right within the main container, with the left div Positioned Relative.

No matter how hard I try, I can't get these div's to touch. I thought it might be an overlapping pagging or margin but i've been staring at the code for hours and it is all starting to blend into one.

Another quickie...

The container does not resize according to the amount of copy contained in either the left or the content div.

Any Ideas would really help!

body {
padding: 0px;
margin: 0px;
text-align: center;
background-color: #fff;
color: #777;
}

#container {
position: relative;
text-align: left;
width: 740px;

}

div.left {
position: relative;
width: 180px;
padding: 1px 0px 0px 0px;
margin: 0px 0px 0px 0px;
height: 100%;
}

div.center {
float: right;
right: 0px;
padding: 13px 40px 0px 0px;
}

I'm probabally missing something real obvious

Thank's again

P

grahamstewart

9:11 am on Apr 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



one problem might be that div.center doesn't have a width set.

A floated box must have an explicit width (assigned via the 'width' property, or its intrinsic width in the case of replaced elements).

- [w3.org...]

Pikin_It_Up

9:36 am on Apr 2, 2004 (gmt 0)

10+ Year Member



Just tried it but no change!

The center div now has a width of 560px;

Bonusbana

9:49 am on Apr 2, 2004 (gmt 0)

10+ Year Member



I think you should try something like this:

body {
padding: 0px;
margin: 0px;
text-align: center;
background: #fff;
color: #777;
}

#container {
position: relative;
text-align: left;
width: 740px;
}

div.left {
float: left;
width: 180px;
margin: 0;
}

div.center {
margin: 0 0 0 180px;
}

And the in the html:

<div id="container">
<div class="left"><p>left content</p><p>left content</p><p>left content</p></div>
<div class="center"><p>right content</p><p>right content</p><p>right content</p></div>
<br style="clear: both;" /> <!-- required for mozilla -->
</div>

In a two-column layout, I think its easier to float the left div, since you can easily specify the width of that div. Then just add a left-margin to the right div.

Maybe this will help you in some way.

david.

[edited by: Bonusbana at 9:52 am (utc) on April 2, 2004]

mipapage

9:51 am on Apr 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Pikin_It_Up,

It appears that you're working in either IE5, 5.5, or IE6-quirks mode, no?

Also, by touch do you mean overlap, or simply sit side by side?

Pikin_It_Up

10:19 am on Apr 2, 2004 (gmt 0)

10+ Year Member



Bonus,

I would like to be able to lay the HTML out like that but i need to have the content div at the top of the HTML(for the SE's).

>It appears that you're working in either IE5, 5.5, or IE6-quirks mode, no?

I'm not sure what you mean Mia, Browser compatability i guess. Could you please expand.;-)

P

Bonusbana

10:33 am on Apr 2, 2004 (gmt 0)

10+ Year Member



By adding a width to the floating center div in your first code, like graham suggested, you should get the desired effect. At least it worked for me in IE/mac & safari. Could you please describe why that doesnt work for you, and what you mean by "the divs doesnt touch".

mipapage

10:46 am on Apr 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure what you mean...

The CSS box model calculates the width of a box by adding any lateral padding to the width of the box. For div.center, you set the width to 560px, which, including the padding-right of 40px equals 600px wide.

So, 600px + 181px = 781px, but your container is 740px.

Now, to complicate things further, IE[win]5 and 5.5 don't add the padding, they include it in the width.

The result is that your mock-up, with a width of 560px, will work in IE[win]5 and 5.5, as well as IE6 in quirks mode, but crack in compliant browsers. You can read up more here [webmasterworld.com].

In addition to the above, you are cenetring your conatiner using a method that only works in Internet explorer. You may want to add "margin:0 auto 0;" to your #container.

Now, how about:

Also, by touch do you mean overlap, or simply sit side by side?

Pikin_It_Up

10:51 am on Apr 2, 2004 (gmt 0)

10+ Year Member



The left div has a backround color of #ccc, the center div has a background color of #777

I want the 2 div's to 'touch' so that there is no white space between them.

As it is, the two div's can sit in line with each other, but with a 10-15 px space between them.

When i try to take that space away, the left div 'jumps' to below the content area

Sorry i'm not all that articulate.

mipapage

11:08 am on Apr 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Okay, sort of a workaround, I suppose, but how about applying the background of the center div to #container?

Then just consider that extra little space 'free padding' ;-]

Pikin_It_Up

11:12 am on Apr 2, 2004 (gmt 0)

10+ Year Member



Here's all the code I have..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>

</head>
<body>
<div id="container">

<div class="topheight">

<!----------------------------------------------main content area------------------------------------->
<div class="center">

</div>

<!----------------------------------------------left content area------------------------------------>
<div class="left">

</div>

</div>

<!----------------------------------------------footer content area------------------------------------->
<div class="footer">

</div>

<!--------------------------------------------navigation content area------------------------->
<div id="nav">

</div>

<!------------------------------------------print and email content area------------------------------->
<div class="functions">
<span class="email"><a href="#">email page</a> <img src="images/mm_mail.gif"></span>
<span class="print"><a href="#">print</a> <img src="images/mm_print.gif"></span>

</div>

<!------------------------------------------close of nav div-------------------------------------------->

</div>

<!----------------------------------------------header content area------------------------------------>
<div id="image">

</div>

<div class="header">

</div>

</div>

</body>
</html>

So that's the html, here's the css

/*-----------------------------------------Body, text and container---------------------------------------------*/

body {
padding: 0px;
margin: 0px;
text-align: center;
background-color: #fff;
color: #777;
font-family: verdana, arial, helvetica, sans-serif;
font-weight: normal;
font-size: 70%;
}

#container {
position: relative;
text-align: left;
width: 740px;

}

div.topheight {
position: relative;
padding-top: 0px;
width: 100%;
top: 141px;
background-color: #EDF1F9;
border: 1px solid black;
height: 100%;
overflow: expand;
}

/*--------------------------------------------------Header------------------------------------------------------*/

#image {
position: absolute;
top: 83px;
}

div.header {
position: absolute;
top: 0px;
width: 740px;
padding-top: 6px;
font-size: 8pt;
height: 20px;
padding-bottom:8px;
border-bottom: 7px solid #ccc;
background-image: url(../images/mm_top.gif);
image-repeat: repeat-x;

}

.functions {
height: 15px;
width: 145px;
float: right;
margin: -3px 5px 0px 0px;
padding: 0px 0px 0px 0px;
}

span.email {
float: left;
}

span.print {
float: right;
}

/*---------------------------------------------------Nav--------------------------------------------------------*/

#nav {
background-image: url(../images/mm_navtwo.gif);
position: absolute;
height: 32px;
top: 51px;
border-top: 1px solid blue;
}

/*---------------------------------------------------Left-------------------------------------------------------*/

div.left {
position: relative;
width: 180px;
padding: 1px 0px 0px 0px;
font-size: 100%;
background-color: #fff;
margin: 0px 0px 0px 0px;
height: 100%;
}

div.head {
padding: 20px 10px 5px 10px;
}

div.top {
padding: 25px 10px 5px 10px;
}

div.bottom {
padding: 20px 10px 5px 10px;
}

/*---------------------------------------------------Main-------------------------------------------------------*/

div.center {
float: right;
width: 565px;
right: 0px;
padding: 13px 40px 0px 0px;
}

div.center {
width: 560px;
voice-family: "\"}\"";
voice-family:inherit;
width: 510px;
}

/*--------------------------------------------------Footer------------------------------------------------------*/

div.footer {
position: relative;
top: 0px
height: 10px;
width: 100%;
text-align: left;
color: #afafaf;
font-size: 90%;
padding: 0px 0px 0px 0px;
background-color: #818181;
border-top: 7px solid #C5C5C5;
}

I hope this explains what it is i wan't to do

Pikin_It_Up

11:14 am on Apr 2, 2004 (gmt 0)

10+ Year Member



mia,

That would work, except at the top of the center div there is an image that must touch the image at the top of the left div.

ie,

The image it split accross two div's, i would like it to look like it's only one image.

Sorry for being such a pain.

Pikin_It_Up

11:42 am on Apr 2, 2004 (gmt 0)

10+ Year Member



Taken the 40px right-padding out of the center div.
Now the space is even bigger?!

I am so confused!

mipapage

12:12 pm on Apr 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The image it split accross two div's, i would like it to look like it's only one image.

Okay, I'm away from my computer for the rest of the day now, so... for the above, if the image is not too large, can you keep it together as one image and either:

  1. Drop it in as a background image in the body element
  2. Drop it into another absolutely positioned div, either as an image in the html (<img src=""...) or as a background image?

Also, check out that link I provided above. It will explain the 40px space you are seeing.

What browser are you using?

Pikin_It_Up

12:20 pm on Apr 2, 2004 (gmt 0)

10+ Year Member



Hey mia,

Good idea, that would save a lot of hassle if i position it at the top of the topheight div. I'll check that link out now.

I'm using ie6 btw.

Thank's again for all of your help.