Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

floats, anyone spot the mistake?

Hi, Im trying to create a two column layout using floats however when i float the elements, the collapse. Having tried a few tips ive read about nothing seems to be working. im using max-width for the first time so not sure if thats the cause...can anyone see where im going wrong?

thanks in advance

HTML

<!DOCTYPE HTML> <html> <head> <link rel="stylesheet" href="css/reset.css"> <link rel="stylesheet" href="css/style.css"> <title> </title> </head> <body> <div id="wrap"> <header> </header> <div id="main"> </div> <div id="side"> </div> </div> </body> </html>

CSS

wrap

{max-width: 1000px; height:1000px; margin: 0 auto; background-color: red; overflow: hidden; position: relative;}

header {height: 150px; max-width:1000px; background-color: blue; margin: 0 auto; }

main {

max-width:700px;
height:100px;
background-color:yellow;
}

side {

max-width:290px;
height:100px;
background-color:green;
}

12 Answers

Post your entire html as well. Please and thank you.

sorry dont know why thats not showing up...itll copy but when the message is posted it goes. its basically a wrap div followed by the header, main then side div

Type you code like this

<body>
   <div id="wrap">
   </div>
</body>

The little ` is located above your Tab key.

Or if anything please post a http://pastebin.com/

See if this helps:

http://jsfiddle.net/cs6Re/

<!DOCTYPE HTML>

<html>

<head>
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/style.css">

<title>

</title>

</head>

<body>

  <div id="wrap">

<header>
</header>



<div id="main">
    </div>


<div id="side">

    </div>
</div>

</body>

</html>

Here you go, let me know if this is what you were looking for.

http://jsfiddle.net/cs6Re/1/

Here is another example that includes a footer. Note that if the footer didn't have the clear:both; attribute, it wouldn't show up.

http://jsfiddle.net/cs6Re/2/

im trying to float the side element to the right so ups along side the main div, when i add the float elements, they collapse

Something like this: http://jsfiddle.net/cs6Re/5/

I think I get what you're trying to do.

What I do is I create a div which will be the working area, where the sidebar and main content will be.

Then put two divs inside it. Assign them the name sidebar and main or whatever and the give the sidebar a width of 25% and the main content a width of 75%. Float one to the left and one to the right.

According to the html you posted... that's not what your doing. Which "div" is your "working" area that you are mentioning?

thats it thanks a lot! so simple but been staring at it for ages!

No problem. Here's how I would do it. http://jsfiddle.net/cs6Re/9/