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
Aaron HARPT
19,845 PointsCss margin
I have a question relating to CSS margin and positioning elements horizontally inline. I was working on a three column layout and was having trouble vertically aligning the three columns. I used negative margin to make them inline and was wondering if that was the correct way of doing it or if there is a better way.
Thanks
3 Answers
rydavim
18,814 PointsI would suggest trying floats for this type of layout. There are many different schools of layout techniques, so this is definitely not the only way to achieve this type of layout.
Here is a quick draft of your layout style using floats instead of negative margins and inline elements. As I said, this is certainly not the only way to achieve this look, but you might find it easier to work with when trying to make your design responsive.
Let me know if you have any questions, floats can sometimes be a bit tricky.
rydavim
18,814 PointsWithout seeing the code in question, it's hard to determine if this is the best method. I personally dislike using negative margins, because I find it difficult to keep track of the ramifications in complex and responsive layouts.
Might floats or relative positioning help you achieve the effect you're looking for?
Aaron HARPT
19,845 PointsHere is a code pen of an example of a two column layout where I used negative margin, when you shrink it down for smaller screen sizes, the columns start looking bad. http://codepen.io/aaronharpt/pen/YXgpyE