CSS CSS Layout Basics CSS Layout Project Column Layout with Media Queries

Mark Bernard
Mark Bernard
2,746 Points

anyone know why my colums are not centered?

not sure why they are not centering.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 87,406 Points

Hi Mark,

Can you post the code you're trying to use, so we can see what's happening?

You can use the markdown cheatsheet which we use to post code to Community forum. Thanks :)

Mark Bernard
Mark Bernard
2,746 Points

CSS

/* ================================= 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%; }

span { margin: 50px; }

/* ================================= 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 { color: #fff; background: #3acec2; }

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

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

.logo { width: 190px; }

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

@media (min-width: 769px) {

.container {
    width: 80%;
    text-align: center;
}

.wrapper {
    min-height: calc(100vh - 89px);
}



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

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

.name {
    float:left;
}

.main-nav {
float:right;
}

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

.banner, .main-footer {
     text-align: center;
}

.banner {
    padding: 3.5em;
    margin-bottom: 50px;
}


.col {
    float: left;
    display: inline-block;
    text-align: center;
}

.primary {
    width: 40%;
    padding-left: 10px;
    padding-right: 10px;
}

.secondary {
    width: 30%;
    padding-left: 10px;
    padding-right: 10px;
}

.tertiary {
    width: 30%;
    padding-left: 10px;
    padding-right: 10px;
}
Mark Bernard
Mark Bernard
2,746 Points

HTML

'''<!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> <div class="wrapper clearfix"> <header class="main-header clearfix"> <h1 class="name"><a href="#">Best City Guide</a></h1> <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> </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="container">

        <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--> 
    </div>
</div>

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

</body> </html>'''

1 Answer

Jason Taylor
Jason Taylor
10,297 Points

If I remember this lesson correctly you were supposed to make 2 media queries one for @media (min-width: 769px){}, and one for @media (min-width: 1025px){}; at 769px you were supposed to have your primary and secondary columns side by side and your tertiary column taken up the full width below them. For 1025px and up you were supposed to have all three columns side by side with the primary column at about 40% and your other columns at 30%.

From what I am looking at it looks like you are trying to get all three columns side by side at the 769px width and you don't have a query for the 1025px at all. If I were you I would reset your code and start from scratch and organize your queries beneath their respective media queries because you piled them all up underneath the clear fix.

primary { width:50%; display:inline-block;

}

.secondary { width:50%; display:inline-block; }

sorry forgot to mention these are the col classes in html not in css. my bad