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

how to align unordered list verticaly center, it's list items are in horizontal position ?

/* CSS Code*/
a{
    text-decoration:none;
}
.main-header{
    margin-top:50px;
border:1px solid red;
text-align:bottom;

}
.name{
    float:left;
    border:1px solid blue;


}
.main-nav{

    float:right;
}
.main-nav li{
    display:inline-block;
    margin-right:15px;
}

.clearfix::after{
    content:"";
    display:table;
    clear:both;
}
/*****************************/
/*HTML Code*/

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Best City Guide</title>
    <link href='https://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <header class="main-header clearfix">

    <h2 class="name">Best City Guide</h2>
        <ul class="main-nav">
            <li class="ice-cream"><a href="#">ice cream</a></li>
            <li><a href="#">donuts</a></li>
            <li class="tea"><a href="#">teay</a></li>
            <li><a href="#">coffee</a></li>
        </ul>

    </header>
</body>
</html>

Moderator edited for formatting: Markdown was added to the question to properly render the code. Please see the Markdown Cheatsheet link at the bottom of the "Add an Answer" section for tips on how to post code to the Community.

1 Answer

Adding a margin-top property to the li's will do the trick.

.main-nav li {
   display: inline-block;
   margin-right: 15px;
   margin-top: 8px;
}

This should help align the list items just change the value until you are happy with it.

i want it to automatically align center