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

I am unable to figure out why my h1 with a border isn't centering

<!DOCTYPE HTML>

<html> <head> <link rel="stylesheet" type="text/css" href="environment.css"> </head>

<body> <header> <h1>Environmentalist Inc.</h1> </header>

<section> </section> <footer> </footer> </body> </html>

CSS

body { background-image: url(Climate-chang-e.jpg); background-size: cover; position: fixed; background-repeat: no-repeat; margin-left: 50px auto; padding: 0; margin: 0 auto; text-align: center; }

h1 { margin: auto; border: 1px solid white; padding: 45px; background-color: hsla(360, 100%, 100%, 0.36); color: white; text-align: center; }

1 Answer

Based upon your other css rules I'm guessing you are trying to set the background image to be fixed, the property should be background-attachment not position. By setting position: fixed in the body rule, you are pretty much setting everything in the body to a fixed position, Because of this the h1 can't center itself.

body { 
    background-image: url(Climate-chang-e.jpg);
    background-color: #000;
    background-size: cover;             
    position: fixed; // <------- Change this 
    background-attachment: fixed; // <-------- To this
    background-repeat: no-repeat;           
    margin-left: 50px auto; 
    padding: 0; 
    margin: 0 auto; 
    text-align: center; 
}