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
melissa brown
4,670 Pointscentering
hi im having trouble with centering. Im trying to only center the h1's eg about, works, and contact but it wont center i though i could just apply text-align center to the h1 section but it doesnt change anything. http://codepen.io/mbrwn/pen/qdvQvv and if i apply text align center to the about-section, works-section and contents section it only centers the contact section.
4 Answers
Frank Friberg
7,704 PointsAs Chyno explained it doesn't center because of the display: inline-block;.
My guess is that you have googled how to underline an H1 element and used their way. But I found another way of doing it:
<h1><span>About Me</span></h1>
I've added the span element to make the border. This elements width is being constrained by the actual width of the H1 element.
h1 {
font-family: 'Raleway', sans-serif;
text-transform: uppercase;
text-align: center;
padding: 1em 2rem;
}
h1 span {
border-bottom: solid black;
padding-bottom: 0.6em;
}
This is the CSS for the border and effect. Hope this helps :)
Chyno Deluxe
16,936 PointsIt won't center because you have h1 set to display: inline-block. Remove it and it will center.
I hope this helps.
melissa brown
4,670 Pointsthanks so much - interesting so inline-block elements do not center? so i originally had inline- block their because i wanted to be able to adjust the bottom border on the h1 and make it just a little bigger than the heading itself. if i remove inline-block the heading covers the entire page. So how would i fix this problem?
Erwin Meesters
15,088 PointsYou can also try this: leave the h1 tags as you you have now. (without span tags and with the display: inline-block) Put this css rule on the parents of the h1 tags (section tags) :
section {
text-align: center;
}