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
Andrew Cresswell
800 Pointsfloats, 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
Ernest Grzybowski
20,401 PointsPost your entire html as well. Please and thank you.
Andrew Cresswell
800 Pointssorry 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
Ernest Grzybowski
20,401 PointsType you code like this
<body>
<div id="wrap">
</div>
</body>
The little ` is located above your Tab key.
Ernest Grzybowski
20,401 PointsAndrew Cresswell
800 Points<!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>
Ernest Grzybowski
20,401 PointsHere you go, let me know if this is what you were looking for.
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.
Andrew Cresswell
800 Pointsim trying to float the side element to the right so ups along side the main div, when i add the float elements, they collapse
Ernest Grzybowski
20,401 PointsSomething like this: http://jsfiddle.net/cs6Re/5/
Matt Campbell
9,767 PointsI 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.
Ernest Grzybowski
20,401 PointsAccording to the html you posted... that's not what your doing. Which "div" is your "working" area that you are mentioning?
Andrew Cresswell
800 Pointsthats it thanks a lot! so simple but been staring at it for ages!
Ernest Grzybowski
20,401 PointsNo problem. Here's how I would do it. http://jsfiddle.net/cs6Re/9/