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

HTML Build a Simple Website Styling Content Writing CSS

Shaunty McMillin
Shaunty McMillin
6,964 Points

Top margin not working?

Did anyone else have trouble getting the top margin to apply to their button while following along? Mine isn't moving at all, and I've even tried entering ridiculous values to see. The margin functions on the left/right, but not the top and for the life of me I can't figure out why.

4 Answers

James Barnett
James Barnett
39,199 Points

Shaunty Linton -

This is actually a known issue with the Smells Like Bakin' project.

The "button" you are trying to style is an <a>, which is an inline element. So any vertical margin (and padding for that matter) that is assigned will not be applied.

Luckily there's a simple fix, just add

.btn { display: inline-block; }
Shaunty McMillin
Shaunty McMillin
6,964 Points

That worked, thank you! :)

Can you post the code you are using here?

sounds like its not a block element, or something like that.

Shaunty McMillin
Shaunty McMillin
6,964 Points

Sure! I'm going to do the relevant parts first, and then post the whole style and html underneath to try and make life easy.

Here's the CSS for the button:

.btn {
    color: #FAF3BC;
    background: #4FB69F url('img/texture.png') no-repeat right top;
    padding: 15px 30px;
    margin: 40px 0px;
}

Here's the links for the stylesheets:

 <link rel="stylesheet" href="css/normalize.css" type="text/css" media="screen" />
  <link rel="stylesheet" href="css/grid.css" type="text/css" media="screen" />
  <link href='http://fonts.googleapis.com/css?family=Nunito' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />

Here's the inline reference to the button:

    <div id="intro" class="grid_9">
      <h1>Opposites really do attract, especially in our kitchen. We combine unexpected flavors that melt together to create ironically delicious desserts</h1>
      <p><a href="#" class="btn">Browse our cupcakes</a></p>
    </div>

Whole Style:

body {
    font-family: 'Nunito', sans-serif;
    color: #FAF3BC;
    background: #420600 url('img/bg-texture.jpg') repeat;
}

a {
    color: #4FB69F;
    text-decoration: none;
}

h1 {
    font-size: 1.750em;
    letter-spacing: -1.5px;
}

h2 {
    font-size: 1.500em;
    color: #B4C34F;
}

.btn {
    color: #FAF3BC;
    background: #4FB69F url('img/texture.png') no-repeat right top;
    padding: 15px 30px;
    margin: 40px 0px;
}

The Full HTML

<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
  <title>Smells Like Bakin' Cupcake Company</title>
  <link rel="stylesheet" href="css/normalize.css" type="text/css" media="screen" />
  <link rel="stylesheet" href="css/grid.css" type="text/css" media="screen" />
  <link href='http://fonts.googleapis.com/css?family=Nunito' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
</head>
<body>
  <div class="container clearfix">
    <div class="grid_4">
      <img src="img/logo.gif" alt="Smells Like Bakin" />
    </div>
    <div class="grid_8 omega">
      <ul class="nav">
        <li><a href="#">About</a></li>
        <li><a href="#">Cupcakes &amp; Prices</a></li>
        <li><a href="#">Locations</a></li>
        <li class="last"><a href="#">Contact Us</a></li>
      </ul>
    </div>
    <div id="intro" class="grid_9">
      <h1>Opposites really do attract, especially in our kitchen. We combine unexpected flavors that melt together to create ironically delicious desserts</h1>
      <p><a href="#" class="btn">Browse our cupcakes</a></p>
    </div>
    <div class="grid_3 omega">
      <img src="img/you-bake-me-blush.gif" alt="You Bake Me Blush" />
    </div>
    <div id="featured-cupcake" class="grid_7">
      <h2>Cupcake of the Week</h2>
      <p>This week's featured cupcake is the <a href="#">Avocado Chocolate Cupcake</a>. Its strange combo of flavors will kick your tastebuds into fiesta mode!</p>
      <img src="img/featured-cupcake.jpg" alt="Avocado Chocolate Cupcake" />
    </div>
    <div id="new-cupcakes" class="grid_5 omega">
      <h2>Fresh Out the Oven</h2>
      <p>Our newest cupcakes are <a href="#">Bacon Me Crazy</a> and <a href="#">Jalapeno So Spicy</a>. </p>
      <img src="img/new-cupcake-bacon.jpg" alt="Bacon Me Crazy" />
      <img src="img/new-cupcake-jalapeno.jpg" alt="Jalapeno So Spicy" />
    </div>
    <div class="grid_7">
      <h2>Inside the Kitchen</h2>
      <p>Smells Like Bakin' started out in the garage of the husband wife duo Allison &amp; Joseph. Allison is the baker, and Joseph found a way for them to make a business out of her tasty treats. Flash forward to today and they have a successful store front, catering business and cupcake truck.</p>
      <p><a href="#" class="btn-small">Read More</a></p>
    </div>
    <div class="grid_5 omega">
      <h2>Get Bakin with Us</h2>
      <div id="contact">
        <p> Call us: <span>1-555-CUP-CAKE</span><br />
          Email Us: <a href="#">bakeon@smellslikebakin.com</a></p>
      </div>
      <p> We announce all of our new flavors first through Facebook &amp; Twitter, and even take requests!</p>
      <a href="http://facebook.com/SmellsLikeBakin"><img src="img/facebook.gif" alt="Facebook" /></a>
      <a href="http://twitter.com/#!/SmellsLikeBakin"><img src="img/Twitter.gif" alt="Twitter" /></a>
    </div>
    <div id="copyright" class="grid_12">
      <p>&copy; 2012 Smells Like Bakin' Cupcake Company. All Rights Reserved.</p>
    </div>
  </div>
</body>
</html>