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

CSS

Border property and margin collapsing

I was curious about others thoughts of applying a transparent 1px border or padding through the universal selector to manage the nature of margin collapsing?

Is there any downside to this?

1 Answer

Well one downside is keeping track of the pixel width and height of elements (including the border). Also, using it on the universal selector (*) could apply it to elements you don't want, and may require more CSS than necessary. A good way around the vertical margin collapse is by wrapping some things other block elements (like divs). but perhaps in practical use use, just use margin-bottom or margin-in-top. And increase it if needed. Really margin collapse is useful, and in actual use it doesn't really come up as a problem, I simply add to padding or margin when needed. I would not recommend using additional padding and transparent border on the universal selector as it requires more code writing in the long run