CSS CSS Layout Basics CSS Layout Project Introducing the Project

Zachary Jackson
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Zachary Jackson
Treehouse Project Reviewer

Vertical alignment issues with containers and floats/inline-blocks

I am having trouble getting items to align vertically in the main header for the Best City Guide CSS challenge. The link to the challenge is the Watch Video above. I also have included my index.html and style.css file to test with down below. I have a container of floated characters inside of a container within the main header. The page's name on the left side of the header "Best City Guide" is centered, but this is because it is the largest element in the container. The container is clearfixed and will take up as much room as it needs to. If I take the clearfix out everything will collapse. I have looked at older CSS content and some of the videos, but I am missing something somewhere. If anyone wants to take a look at my project I would appreciate it.

Zachary Jackson
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Zachary Jackson
Treehouse Project Reviewer
/* =================================
  Base Element Styles
==================================== */

* {
    box-sizing: border-box;
}

body {
    font-family: 'Varela Round', sans-serif;
    line-height: 1.6;
    color: #3a3a3a;
}

p {
    font-size: .95em;
    margin-bottom: 1.8em;
}

h2,
h3,
a {
    color: #093a58;
}

h2,
h3 {
    margin-top: 0;
}

a {
    text-decoration: none;
}

img {
    max-width: 100%;
}

/* =================================
  Base Layout Styles
==================================== */

/* ---- Navigation ---- */

.name {
    font-size: 1.25em;
}

.name a,
.main-nav a {
    text-align: center;
}

.main-nav a {
    font-size: .95em;
    color: #3acec2;
    text-transform: uppercase;
}

.main-nav a:hover {
    color: #093a58;
}

/* ---- Layout Containers ---- */

.banner {
    text-align: center;
    color: #fff;
    background: #3acec2;
}

.main-footer {
    background: #d9e4ea;
    padding: 2em 0;
    margin-top: 30px;
}

/* ---- Page Elements ---- */

.logo {
    width: 190px;
    margin-top: 1em;
}

.headline {
    margin:0;
    margin-top: .4em;
}

.tagline {
    display: inline-block;
    margin-bottom: 1.6em;
}

/* =================================
  Media Queries
==================================== */

@media (min-width: 769px) {

    .container {
        width: 90%;
        margin: 0 auto;
    }

    .name {
        display: inline;
    }

    .main-nav {
        float:right;
    }

    .main-nav li {
        float: left;
        margin-left: 10px;
    }



    /* ---- Float clearfix ---- */

    .clearfix::after {
        content: " ";
        display: table;
        clear: both;
    }

}
Zachary Jackson
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Zachary Jackson
Treehouse Project Reviewer
<!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">
        <div class ="container clearfix">
            <h1 class="name"><a href="#">Best City Guide</a></h1>
            <div class="container-main-nav">
                <ul class="main-nav">
                    <li><a href="#">ice cream</a></li>
                    <li><a href="#">donuts</a></li>
                    <li><a href="#">tea</a></li>
                    <li><a href="#">coffee</a></li>
                </ul>
            </div><!--/.container-main-nav clearfix-->
        </div><!--/.container clearfix-->
    </header><!--/.main-header-->

    <div class="banner">
        <img class="logo" src="img/city-logo.svg" alt="City">
        <h1 class="headline">The Best City</h1>
        <span class="tagline">The best drinks and eats in the best city ever.</span>
    </div><!--/.banner-->

    <div class="secondary col">
        <h2>Welcome!</h2>
        <p>Everything in this city is worth waiting in line for.</p>
        <p>Cupcake ipsum dolor sit. Amet chocolate cake gummies jelly beans candy bonbon brownie candy. Gingerbread powder muffin. Icing cotton candy. Croissant icing pie ice cream brownie I love cheesecake cookie. Pastry chocolate pastry jelly croissant.</p>
        <p>Cake sesame snaps sweet tart candy canes tiramisu I love oat cake chocolate bar. Jelly beans pastry brownie sugar plum pastry bear claw tiramisu tootsie roll. Tootsie roll wafer I love chocolate donuts.</p>
    </div><!--/.secondary-->

    <div class="primary col">
        <h2>Great food</h2>
        <img class="feat-img" src="img/treats.svg" alt="Drinks and eats">
        <p>Croissant macaroon pie brownie. Cookie marshmallow liquorice gingerbread caramels toffee I love chocolate. Wafer lollipop dessert. Bonbon jelly beans pudding dessert sugar plum. Marzipan toffee drag&#233;e chocolate bar candy toffee pudding I love. Gummi bears pie gingerbread lollipop.</p>
    </div><!--/.primary-->

    <div class="tertiary col">
        <h2>How to get here</h2>
        <p><strong>Plane: </strong>Tiramisu caramels gummies chupa chups lollipop muffin. Jujubes chocolate caramels cheesecake brownie lollipop drag&#233;e cheesecake.</p>
        <p><strong>Train: </strong>Pie apple pie pudding I love wafer toffee liquorice sesame snaps lemon drops. Lollipop gummi bears dessert muffin I love fruitcake toffee pie.</p>
        <p><strong>Car: </strong>Jelly cotton candy bonbon jelly-o jelly-o I love. I love sugar plum chocolate cake pie I love pastry liquorice.</p>
    </div><!--/.tertiary-->

    <footer class="main-footer">
        <span>&copy;2015 Residents of The Best City Ever.</span>
    </footer>

</body>
</html>
Steven Parker
Steven Parker
204,853 Points

To format your code in a code box, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

But a much better way to share a project is to make a snapshot of your workspace and post the link to it here. This is particularly useful for a project like this one that relies on additional resources such as graphic elements.

Zachary Jackson
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Zachary Jackson
Treehouse Project Reviewer

Thanks Steven Parker for the information about formatting code. I completely missed that Markdown Cheatsheet reference.

1 Answer

Steven Parker
Steven Parker
204,853 Points

Are you talking about how "Best City Guide" and the nav items are on different lines? To make them vertically aligned, you can set ".name" to "float: left". And then you won't need to change the "display" property because floating it makes it not participate in normal positioning.

If that's not it, perhaps you could explain the issue in different terms.

Also, you might consider proceeding with the next few videos as they show sample formatting solutions which might answer your questions.

Zachary Jackson
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Zachary Jackson
Treehouse Project Reviewer

You are correct that I was talking about how the "Best City Guide" and the nav items are on different lines vertically. I will continue on to the solution video as suggested. While I knew those videos where there I was trying to avoid watching them somewhat until I finished with all or most of this project. However, I don't think there is any shame in continuing on if one is stuck especially if the video will help things click into place. Thanks again Mr Parker.