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 Margin properties are not applying to div elements

I am trying to set margin property for two div elements. But i could not set them. My HTML and CSS codes are below.

   <body>
        <div class="container">
            <div class="link">
                <a href="#"class="welcomemessage">Welcome To India</a>
            </div>
            <div class="list">
                <ul>
                    <li>Welcome</li>
                    <li>Welcome</li>
                    <li>Welcome</li>
                    <li>Welcome</li>
                    <li>Welcome</li>
                </ul>
            </div>
        </div>
    </body>
.list{
    margin: 10px auto;
}

.link{
margin: 10px auto;
}

I even tried to set for class("container"). But no success.

Can anyone here help me please?

Thanks in advance,

Regards

1 Answer

Hey,

The HTML should work if you do this, using a h1 element.

<!DOCTYPE html>
<html>
    <head>
        <title>N-th Child Pseudo Selector</title>
        <link rel="stylesheet" href="pseudoclass.css"/>
    </head>
    <body>
        <div class="container">
            <h1>
                <a href="#">Welcome To India</a>
            </h1>
            <div class="list">
                <ul>
                    <li>Welcome</li>
                    <li>Welcome</li>
                    <li>Welcome</li>
                    <li>Welcome</li>
                    <li>Welcome</li>
                </ul>
            </div>
        </div>
    </body>
</html>

and this CSS;

body{
    background-color: #ccc;
}

h1 {
    text-align: center;
}

.list {
    margin: 0 auto;
    width: 10%;
}

=)

I do understand with div elements now. Because div elements basically take the width of the browser screen.

I tried with anchor element. By default, anchor elements are inline. So I expect it to move to center when I set margin vertical to auto.

a{
   margin: 0px auto;
}

Even this one does not work.