Learn Typography by Building a Nutrition Label - Step 23

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Nutrition Label</title>
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700,800" rel="stylesheet">
  <link href="./styles.css" rel="stylesheet">
</head>

<body>
  <div class="label">
    <h1 class="bold">Nutrition Facts</h1>
    <div class="divider"></div>
    <p>8 servings per container</p>
    <p class="bold">Serving size <span>2/3 cup (55g)</span></p>
  </div>
</body>
</html>
/* file: styles.css */
* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  font-family: 'Open Sans', sans-serif;
}

.label {
  border: 2px solid black;
  width: 270px;
  margin: 20px auto;
  padding: 0 7px;
}

h1 {
  text-align: center;
  margin: -4px 0;
  letter-spacing: 0.15px
}


/* User Editable Region */

p {
  margin: 0;
}

/* User Editable Region */


.divider {
  border-bottom: 1px solid #888989;
  margin: 2px 0;
}

.bold {
  font-weight: 800;
}

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 11; Redmi Note 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36

Challenge: Learn Typography by Building a Nutrition Label - Step 23

Link to the challenge:

Can you describe what you are having difficulty understanding please?

1 Like

Hi. Thanks for replying. I’m a bit confused about something.

Let me explain
In the block of code above there are two p elements but the second one has a span element around some part of it’s content.
The issue now is that after styling the p with the style below

p {
display: flex;
justify-content: space-between;
}

only the p element with the span tag got affected by this tag.
Why is this so?

So you’ve solved the challenge?

I don’t know how familiar you are with CSS flex (or grid for that matter) but applying display: flex to an element turns it into a flex container. This means that you can control the layout of its child elements (i.e. any elements which are nested inside the flex container) using flex properties.

The second <p> element has a span, so the space-between justification makes the items inside the <p> fill the width of the container, putting the available space between the items (i.e. the text ‘Serving size’ and the <span> element).
The first <p> element has no child elements, only text content. So flex properties have nothing to put space-between.

1 Like

I’ve been finding an answer to this for a while now, but you just explained it the best way! Thank you so much.
By the way, I’m new to css so i didn’t know that’s how flexbox works

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