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 trialDavid Pinner
7,039 PointsFloat aaaaaahhhhhhh
ok so heres the picture, made it though CSS basics course with a little help from this community "massive thanks" but is till don't understand the float concept, as in I can not get it to work on my own, on my web page I am designing.
the basics is I would see it is column A class="a col" and column B class="b col" to sit next to each other.
" this is my basic look at it" in theory it sounds easy .col a { float: left; margin-right: 10px} .col b {float: right; margin-left 10px}
now even on a very basic page consisting of just two columns I cannot get them to float next to each other using the css code below, can someone please explain the code to make these two basic columns float next to each other.
your help is greatly appreciated as this has been driving me nuts all day
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, David Pinner! I feel like you and I are going to have to agree to disagree on one thing: your understanding of floats. It seems to me that you understand them just fine. But if that's your actual code, there are a couple of things that are a bit off. First, you have class="col a"
. This means that that element has a class of "col" and a class of "a". I believe what you meant here was class="col-a"
which is just one class named "col-a". I believe the same is true for class="col b"
.
Secondly, your selectors are a bit off. In the first one, you are selecting every anchor tag within an element that has a class of "col" by this selector:
.col a {
/* some code here */
}
This selects every link inside any element that has the class of "col". I feel like what you meant to do here was select every element with the class "col-a". The same is true of your second rule except that it is selecting every <b>
element, and there is no such thing in HTML Finally, you have a missing colon after your margin-left
in your second rule.
Also note that the items you plan to float will have to be put in some sort of container that has a width specified so that it knows where the right and left are. I wrote these up and hope these will help. I think you'll be surprised how close you actually are.
<div class="main-div">
<div class="col-a">
<p>Red box</p>
</div>
<div class="col-b">
<p>Blue box</p>
</div>
</div>
.main-div {
width: 100vw;
}
.col-a {
float: left;
margin-right: 10px;
background-color: red;
}
.col-b {
float: right;
margin-left: 10px;
background-color: blue;
}
div {
width: 150px;
height: 150px;
}
Hope this helps!
David Pinner
7,039 PointsDavid Pinner
7,039 PointsJennifer Nordell, thank you for that it makes sense now, I was getting my coding all mixed up and spent too long trying to work it out so missed the basics.
Tony B
Front End Web Development Techdegree Student 10,702 PointsTony B
Front End Web Development Techdegree Student 10,702 PointsThank you! I was having the same problem and super stuck. The container width unstuck me!