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

Dewayne Thomas
PLUS
Dewayne Thomas
Courses Plus Student 10,283 Points

Centering a Header in a Div tag

Hi, I have a problem centering a header thats in a div tag(HTML). It centers in my text editor, but when I upload it to the webhosting, and I view it live, its not centered. I've been going over it line for line, in both the html and the css for 2 weeks now, and no luck. Please help.

Here are lines of my html: <header> <h1>Baby Beatzz Countdown</h1> <div id="clockdiv"> <----THIS IS WHAT I'M TRYNA CENTER <div> <span class="days"></span> <div class="smalltext">Days</div> </div> <div> <span class="hours"></span> <div class="smalltext">Hours</div> </div> <div> <span class="minutes"></span> <div class="smalltext">Minutes</div> </div> <div> <span class="seconds"></span> <div class="smalltext">Seconds</div> </div> </div>

</header>

Lines Of my CSS:

clockdiv{

font-family: sans-serif;
color: #fff;
display: inline-block;
font-weight: 100px;
text-align: center;
font-size: 30px;

}

clockdiv > div{

padding: 10px;
border-radius: 3px;
display: inline-block;
text-align: center;

}

clockdiv div > span{

padding: 15px;
border-radius: 3px;
    display: inline-block;
    text-align: center;

}

.smalltext{ padding-top: 5px; font-size: 16px; text-align: center; }

3 Answers

Denny Schouten
Denny Schouten
8,246 Points

hi, have you tried margin: 0 auto; for your clockdiv element?

Denny Schouten
Denny Schouten
8,246 Points

oh and add a width to the clockdiv

Dewayne Thomas
Dewayne Thomas
Courses Plus Student 10,283 Points

It worked when I added the width. I added 500px to the width, and it centered its ass up. Thanks bud. My 2weeks of almost jumping off a bridge is no more. You code talked me off the ledge.

Denny Schouten
Denny Schouten
8,246 Points

I'm glad it worked out fine! Good thing you didn't jump! ;)