Learn CSS Colors by Building a Set of Colored Markers - Step 15

Tell us what’s happening:
Okay maybe a dumb question, actually two questions:

  1. When I set the shorthand margin to auto shouldn’t that align my marker to the exact center of the body? I mean so far, no parameters dictating the size of the div element have been set? Then why is it aligned top-center?
  2. In the previous project when we were supposed to pick a fallback font for h1 and h2 element, we needed to use a comma to separate the fonts. Why don’t I need a comma when providing two different values (10px and auto) for margin? Is it because one is an integer?

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>Colored Markers</title>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
    <h1>CSS Color Markers</h1>
    <div class="container">
      <div class="marker">
      </div>
      <div class="marker">
      </div>
      <div class="marker">
      </div>
    </div>
  </body>
</html>
/* file: styles.css */
h1 {
  text-align: center;
}


/* User Editable Region */

.marker {
  width: 200px;
  height: 25px;
  background-color: red;
  margin: 10px auto;
}

/* User Editable Region */


Your browser information:

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

Challenge: Learn CSS Colors by Building a Set of Colored Markers - Step 15

Link to the challenge:

Welcome to our community!

  1. The ‘height’ property here defines the height of the div elements with the .marker class. The ‘margin’ property sets to auto centers horizontally all ‘div’ elements within their container (which is the ‘div’ element with the ‘class’ attribute set to the value of “container”)
  2. Only the first font will be applied to the headings. If it is not recognized by the browser, a fallback font applies. That is why you separate them by a comma. The ‘margin’ property may have up to four different values and all apply as one css rule. So, for the margin property, you don’t use a comma to separate values.

Thanks a lot! I will keep it in mind :slight_smile:

1 Like

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