Learn Basic CSS by Building a Cafe Menu - Step 54

Tell us what’s happening:

I’ve added the same padding value to the sides, and the top and bottom of <div class="menu"> i.e. 20px. Why is it that the padding on top and bottom appears more than the padding on the sides?

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Cafe Menu</title>
    <link href="styles.css" rel="stylesheet"/>
  </head>
  <body>
    <div class="menu">
      <main>
        <h1>CAMPER CAFE</h1>
        <p>Est. 2020</p>
        <section>
          <h2>Coffee</h2>
          <article class="item">
            <p class="flavor">French Vanilla</p><p class="price">3.00</p>
          </article>
          <article class="item">
            <p class="flavor">Caramel Macchiato</p><p class="price">3.75</p>
          </article>
          <article class="item">
            <p class="flavor">Pumpkin Spice</p><p class="price">3.50</p>
          </article>
          <article class="item">
            <p class="flavor">Hazelnut</p><p class="price">4.00</p>
          </article>
          <article class="item">
            <p class="flavor">Mocha</p><p class="price">4.50</p>
          </article>
        </section>
        <section>
          <h2>Desserts</h2>
          <article class="item">
            <p class="dessert">Donut</p><p class="price">1.50</p>
          </article>
          <article class="item">
            <p class="dessert">Cherry Pie</p><p class="price">2.75</p>
          </article>
          <article class="item">
            <p class="dessert">Cheesecake</p><p class="price">3.00</p>
          </article>
          <article class="item">
            <p class="dessert">Cinnamon Roll</p><p class="price">2.50</p>
          </article>
        </section>
      </main>
    </div>
  </body>
</html>
/* file: styles.css */
body {
  background-image: url(https://cdn.freecodecamp.org/curriculum/css-cafe/beans.jpg);
}

h1, h2, p {
  text-align: center;
}


/* User Editable Region */

.menu {
  width: 80%;
  background-color: burlywood;
  margin-left: auto;
  margin-right: auto;
  padding-left: 20px;
  padding-right: 20px;
  padding-top: 20px;
  padding-bottom: 20px;
}

/* User Editable Region */


.item p {
  display: inline-block;
}

.flavor, .dessert {
  text-align: left;
  width: 75%;
}

.price {
  text-align: right;
  width: 25%
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0

Challenge Information:

Learn Basic CSS by Building a Cafe Menu - Step 54

Hi @ayushpandeyv172050 ! Welcome back.

Have you checked your margin, border and padding properties? I believe they may cause this.

2 Likes

Yeah I actually tried setting all other values to 0 to see how it would affect the outcome. I did learn that the browser adds some space above and below <h1>, <h2> and such by default. But then again, even the bottom padding which is just below a <p> element also looks more than that at the sides. Screenshot attached below:
Web capture_20-12-2023_153830_www.freecodecamp.org

What I am more interested in understanding is this: As I understand, 20px is supposed to count 20 pixels from top/bottom/sides (wherever I apply it) and add that much padding/margin. Do I have that right? And my logic tells me that 20 pixels (if that’s what px even means) horizontally and vertically should be same, right?

Also, thanks a bunch for the response and welcome :slight_smile:

It actually addresses this in step 84 :slight_smile:

1 Like

Actually the comment you deleted was more helpful for the likes of me, haha. Yeah, I remember coming across that and reading the browser adds some space above <h1> etc. by default. I just got confused because there was also more space at the end of the menu (below the <p> element). Went back and checked, there was already more space on the top and bottom in comparison to the side, for some reason.

Thanks a lot :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.