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
Demian Arend
3,386 PointsWhy are floats and clears troublesome?
I can't seem to clear my floats properly. In the following code I want the paragraphs to come up a line and sit beside their respective pictures but I can never seem to properly clear the first float. Everything that follows gets jumbled up. Any insight would be appreciated. Thanks. Here's the page I'm working on:
<!DOCTYPE html> <html lang="en">
<head> <meta content="ko" http-equiv="Content-Language" /> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Dishes</title>
<style type="text/css">
body {
background-color: rgba(65, 105, 240, .7);
background-image: url('Seamless-P.jpg');
background-repeat: no-repeat;
background-position: 50% 20%;
background-size: 90%;
background-attachment: fixed;
}
h1 {
font-family: verdana, arial, sans-serif;
font-size: 3em;
color: pink;
text-shadow: 3px 3px 4px purple;
text-align: center;
}
.nav {
font-family: courier, courier new, monospace;
font-size: 1.1em;
color: pink;
text-shadow: 1px 1px 2px black;
width: 200px;
/*border: 3px solid pink;*/
background: rgba(65, 105, 240, .6);
background-position: 100px 50%;
background-repeat: no-repeat;
}
.firstpic {
border: 5px solid pink;
background-color: blue;
margin: 10px;
/*float: left;*/
}
.p1 {
font-size: 1.7em;
margin-left: 20px;
}
.secondpic {
border: 5px solid pink;
background-color: blue;
margin: 10px;
clear: left;
}
.p2 {
font-size: 1.7em;
margin-left: 20px;
}
.thirdpic {
border: 5px solid pink;
background-color: blue;
margin: 10px;
}
.p3 {
font-size: 1.7em;
margin-left: 20px;
}
.fourthpic {
border: 5px solid pink;
background-color: blue;
margin: 10px;
}
.p4 {
font-size: 1.7em;
margin-left: 20px;
}
.fifthpic {
border: 5px solid pink;
background-color: blue;
margin: 10px;
}
.p5 {
font-size: 1.7em;
margin-left: 20px;
}
.sixthpic {
border: 5px solid pink;
background-color: blue;
margin: 10px;
}
.p6 {
font-size: 1.7em;
margin-left: 20px;
}
.footer {
margin-left: 100px;
margin-right: 100px;
background: rgba(65, 105, 240, .6);
text-align: center;
font-family: courier, courier new, monospace;
font-size: 1.1em;
color: pink;
text-shadow: 1px 1px 2px black;
}
a:link {
color: pink;
}
a:hover {
color: white;
}
a:visited {
color: red;
}
a {
text-decoration: none;
}
</style>
</head>
<body>
<h1>Dishes</h1>
<ul class="nav">
<a href="index.html"><li>Home</li></a>
<a href="About Me and My Service.html"><li>About Me and My Service</li></a>
<a href="A Description of Korean Cuisine.html"><li>A Description of Korean Cuisine</li></a>
<a href="A Couple Recipes.html"><li>A Couple Recipes</li></a>
<a href="Photos of Korea.html"><li>Photos of Korea</li></a>
<a href="Contact.html"><li>Contact</li></a>
</ul>
<br> <br> <br>
<img class="firstpic" src="Bibimbap_2175.png" alt="Bibimbap" height="275" width="200"><p class="p1">
<p class="p1">This is Homemade Bibimbap. It is a mix of rice, egg, gochujung (a spicy, red, bean paste) seaweed, bean sprouts and other vegetables mixed together. It is one of the healthiest of all Korean foods.</p>
<br>
<br>
<img class="secondpic" src="Kimchi (Radish and Cabbage)_2176.png" alt="Kimchi" height="275" width="200">
<p class="p2">This is Kimchi. It is, perhaps, Korea's most famous dish. It is a spicy side dish served with virtually everything. There are two main types: one made from cabbage and another made from radishes. The Kimchi you see her is a combination of both types.</p>
<br> <br>
<img class="thirdpic" src="Bulgogi.png" alt="Bulgogi (Korean Beef)" height="200" width="275">
<p class="p3">This is Bulgogi. It is another Korean standard. It is a beef marinated in soy sauce, garlic, and a little bit of sugar and cooked on a stove with a little water in the bottom of the pan. It is served with a sprinkling of sesame seeds and is delicious!</p>
<br> <br>
<img class="fourthpic" src="Den Jang Jiggae_2167.png" alt="Korean Soup" height="275" width="200">
<p class="p4">This is Korea's most popular soup, Den Jang Jiggae. It is a bit similar to Japan's famous miso soup, but it is surely not the same. Den Jang, a soy bean paste, is the basic ingredient along with Korean celery, seaweed, scallion, and a lot of tofu. It is very healthy!</p>
<br> <br>
<img class="fifthpic" src="Dak Jim.png" alt="Dak Jim (Korean Chicken Stew)" height="200" width="275">
<p class="p5">This is Dak Jim: a Korean chicken stew. It consists of chicken, potato, onion, carrot, scallion, some soy sauce, spicy red bean paste (gochujung), and some noodles. It's boiled and it's fantastic, a favorite of many Korean cuisine lovers!</p>
<br> <br>
<img class="sixthpic" src="Dah Guk.png" alt="Dak Jim (Korean Chicken Stew)" height="200" width="275"> <p class="p4">This is Dah Guk. It is made with egg, seeweed, and dah. Dah is a chewy, slightly sweet rice dough, a Korean specialty. The broth is a mix of these flavors.</p>
<br>
<div class="footer">
<a href="index.html">Home</a> | <a href="About Me and My Service.html">About Me and My Service</a> | <a href="A Description of Korean Cuisine.html">A Description of Korean Cuisine</a> | <a href="Dishes.html">Dishes</a> | <a href="A Couple Recipes.html">A Couple Recipes</a> | <a href="Contact.html">Contact</a>
<br>
<p>©Seongwon's Korean Cooking</p>
</div>
</body>
</html>
2 Answers
Jonathan Roosa
4,456 PointsMaybe the forum didn't show all of your code, but are you using / have you tried using the Micro Clearfix Hack?
It's the only way I clear my floats and it seems to work flawlessly.
Demian Arend
3,386 PointsHey Jonathan. Thanks, for replying. I found an answer on line even before you responded. It worked. I needed to place a empty div in between items in the HTML mark up:
<div style="clear: both;"></div>
It worked well and the paragraphs have now floated up beside their respective pictures. I will still take a look at your link, however. Thanks, Demian