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 CSS Basics (2014) Basic Layout box-sizing and max-width

Sandeep Singh
Sandeep Singh
3,582 Points

Hi , image gallery is not in center of the page.

Hi , i am facing this problem every time with my coding . The problem is - alignment of header and footer's text or image always in center of the page with property text-align .But , alignment of image gallery is not in the center of the page.Its slight left or right side depend on the size of the page. If i use wrapper to warp all code with text align property then the same problem what is wrong with this coding below -

<!DOCTYPE html>
<html>
<head>
    <title>---------</title>
    <link rel="stylesheet" href="main.css">

</head>
<body>
    <nav>
        <ul id="mainMenu">
            <li><a href="#">------------</a></li>
            <li><a href="#">------------</a></li>
            <li><a href="#">------------</a></li>
            <li><a href="#">------------</a></li>
            <li><a href="#">------------</a></li>
        </ul>
    </nav>
    <header>
        <h2 id="mainHeading">------------</h2>
        <!-- <h2 id="wild"><a href="#">------------</a></h2> -->
    </header>
        <ul id="gallery">
            <li><img src="img/------------.jpg"></li>
            <li><img src="img/T------------.jpg"></li>
            <li><img src="img/------------.jpg"></li>
            <li><img src="img/------------.jpg"></li>
        </ul>

    <footer>
        <a href="https://------------        " target="_blank"><img src="img/facebook-wrap.png" class="icon"></a>
        <a href="https://------------  " target="_blank"><img src="img/twitter-wrap.png" class="icon"></a>
        <P>------------ . </P>
    </footer>

</body>
</html>   ```html

here ..css file -

```css
* {
    box-sizing: border-box;

}
body{
    margin: 0;

}
img{
    max-width: 100%;
}
a{
    text-decoration: none;
    color: #696969;
}
 nav ul{
    list-style: none;
    text-align: center;
    padding-left:0.10em;
}#mainMenu li{
    padding: 5px;
}
    header{
    background-image: url("img/sys.jpg");
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    text-align: center;
    margin: 0 0 15px 0;
    /*width: 100%;*/
    height: 500px;
}#mainHeading{
    font-size: 32px;
    /*text-align: center;*/
    color: #fff;
    border-bottom: 1px solid;
    padding: 0 0 5px;
    margin: 140px 0 0 0;
    display: inline-block;

}#gallery{
    list-style: none;

}#gallery li{
    width: 45%;
    float: left;
    margin: 2.5px;
}
footer{
 text-align: center;
 clear: both;
}
.icon{
    padding: 5px;
    width: 45px;
    height: 45px;

}```
Matthew Lang
Matthew Lang
13,483 Points

Your #gallery is floated left. This takes your gallery out of the usual layout of the page and glues it to the left side.

2 Answers

Cosmin Ionut Mindru
Cosmin Ionut Mindru
2,110 Points

Add the property "margin: auto" to your "nav ul" selector.

Sandeep Singh
Sandeep Singh
3,582 Points

How to make it in center of the page?