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 How to Make a Website CSS: Cascading Style Sheets Style the Basic Elements

margin centering

Hi, a bit confused on what margin really does and how I could center my wrapper with margin?

2 Answers

Reuben Varzea
Reuben Varzea
23,182 Points

Margin is the white space around your object. So, if you were looking to center something, that "something", like wrapper, would itself need to have a size defined, and then you can assign values to the margins to center it. Keep in mind that if you don't know what the values should be for margin, there is a value you can use to cover yourself regardless of browser window size.

jake anderson
jake anderson
6,017 Points

define a percentage width and height then use margin:auto; to center as shown below

.wrapper { position: relative; width: 80%; height: 60%; background: #00000; margin: auto; }