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 trialAmanda Quintero
7,015 PointsFor the Float Challenge -- I got this solution, got what I needed but is it correct?
This is the full code
https://teamtreehouse.com/workspaces/39295992
And this is:
/* My solution */
.col + .col {
padding-left: 1em; }
.col:first-child { padding-left: 0; float: left; width: 40%; vertical-align: top; padding-left: 1em; padding-right: 1em; padding-bottom: 5px; }
.col:last-child { padding-right: 0; float: right; width: 60%; vertical-align: top; padding-left: 1em; padding-right: 1em; padding-bottom: 5px; }
Amanda Quintero
7,015 Points1 Answer
Steven Parker
231,248 PointsIt looks like you accomplished the objective, good job!
In programming, there's rarely only one "correct" way to do anything. But there are a few ways you can improve and optimize. When elements share the same class, you can avoid repeating yourself (known as making your code "DRY") by placing all the common attributes in one rule. Doing that here would look like this:
.col {
float: left;
vertical-align: top;
padding-left: 1em;
padding-right: 1em;
padding-bottom: 5px;
}
.col:first-child {
width: 40%;
}
.col:last-child {
width: 60%;
}
This also replaces the adjacent sibling rule (".col + .col"). And it isn't necessary to float the columns on different sides, so I just let them share a "left" float.
In the next video you'll see how the instructor makes use of the unique classes of "primary" and "secondary" instead of the pseudo classes. But your use of the pseudo-classes is clever, and would be the perfect thing in situations where the elements don't have unique classes.
Keep up the good work, and happy coding!
Amanda Quintero
7,015 PointsThank you for your input. I really appreciate it.
Steven Parker
231,248 PointsSteven Parker
231,248 PointsThe direct link to your workspace is temporary and only exists while you are using it, but you can make a snapshot (note: not "screenshot") of your workspace and post the link to it here.