123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <header>
  <h1>CSS Margin Test - Solved</h1>
</header>

<form action="" id="my-form">
  <p>
    This page contains three main parent elements - a header, a form, and a footer. They each contain child elements.
  </p>
  <p>
    Each of the three main elements have been given these margin and padding rules:
    <xmp>
      margin: 0 auto 0 auto;
      padding: 0;
    </xmp>
  </p>
  <p>
    I didn't understand why giving the <strong>h1</strong> and/or the <strong>p</strong> child elements a margin of more than zero affects the margin of the parent elements, causing a gap between the header and/or footer and the form.
  </p>
  <p>
    Note that I visited the <a href="https://www.w3schools.com/cssref/css_default_values.asp" target="_blank">https://www.w3schools.com/cssref/css_default_values.asp</a> page to look up the default CSS values for forms and they don't use negative values by default.
  </p>
  <p>
    Solved. The <a href="https://stackoverflow.com/questions/20689575/css-margin-top-of-h1-affects-parents-margin" target="_blank">https://stackoverflow.com/questions/20689575/css-margin-top-of-h1-affects-parents-margin</a> and <a href="https://css-tricks.com/what-you-should-know-about-collapsing-margins/" target="_blank">https://css-tricks.com/what-you-should-know-about-collapsing-margins/</a> pages explain that vertical margins can conflict, and the larger of the two is chosen by default. A couple of ways to overcome this are to use the overflow: hidden or overflow: auto rule or set explicit margins that counteract the defaults.
  </p>
  <label id="name=label" for="name">Name: </label>
  <input id="name" name="name" type="text" placeholder="name of person" required></input>
  <br>
  <br>
  <label id="email-label" for="email">Email: </label>
  <input id="email" name="email" type="email" placeholder="valid email address of person" required></input>
  <br>
  <br>
  <label id="age-label" for="number">Age: </label>
  <input id="age" min="18" max="100" name="age" type="number" placeholder="age from 18 - 100"></input>
  <br>
  <br>
  <input type="submit" value="SUBMIT"></input>
  <input type="button" value="RESET" onClick="resetForm();"></input>
</form>

<footer>
  <p>
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed doeiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enimad minim veniam, quis nostrud exercitation ullamco laboris nisi utaliquip ex ea commodo consequat. Duis aute irure dolor inreprehenderit in voluptate velit esse cillum dolore eu fugiat nullapariatur. Excepteur sint occaecat cupidatat non proident, sunt inculpa qui offi.
  </p>
</footer>

            
          
!
            
              * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  }
body {
  margin: 0;
  padding: 0;
  }
footer {
  background-color: dodgerblue;
  display: block;
  margin: 0 auto 0 auto;
  padding: 0;
  width: 60%;
  }
form {
  background-color: powderblue;
  display: block;
  margin: 0 auto 0 auto;
  padding: 0;
  width: 60%;
  }
h1 {
	/*
	margin: 1em;
	margin: 1em 0 1em 0;
	margin: 1em auto 1em auto;
	*/
	}
header {
	background-color: dodgerblue;
	display: block;
	margin: 0 auto 0 auto;
	padding: 0;
	text-align: center;
	width: 60%;
	}
p {
	/*
	margin: 1em;
	margin: 1em 0 1em 0;
	margin: 1em auto 1em auto;
	*/
	}
            
          
!
            
              function resetForm() {
  document.getElementById("my-form").reset();
  }
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console