Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h2>규칙</h2>
<p>블록의 위아래 여백은 각 여백중 더 큰 것으로 결합(병합)됩니다. 이를 마진 병합(Margin Collapsing)이라고 합니다. float되거나 absolute로 배치된 요소의 마진은 절대 병합되지 않습니다.</p>
<p>참고: <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_box_model/Mastering_margin_collapsing">Mastering margin collapsing(MDN)</a></p>
<h2>위아래 마진은 병합된다</h2>
<p>👇뒤의 요소가 float 요소 뒤에서 clear 속성을 사용하지 않은 경우</p>
<div class="test-block  flex" style="margin-bottom: 50px; background-color: gold;">
  margin-bottom: 50px
</div>
<div class="test-block  flex" style="margin-top: 50px; background-color: skyblue;">
  margin-top: 50px
</div>

<p>👇뒤의 요소가 float 요소 뒤에서 clear 속성을 사용한 경우는 예외</p>
<div class="test-block  flex" style="margin-bottom: 50px; background-color: gold;">
  margin-bottom: 50px
</div>
<div class="float" style="float: left; height: 30px; background-color: lightgray; padding: 5px;">float: left</div>
<div class="test-block  flex  clear" style="margin-top: 50px; background-color: skyblue;">
  margin-top: 50px
</div>

<p>👇뒤의 요소가 float 요소 뒤에서 clear 속성을 사용 안 한 경우는 마진 병합이 작동</p>
<div class="test-block  flex" style="margin-bottom: 50px; background-color: gold;">
  margin-bottom: 50px
</div>
<div class="float" style="float: left; height: 30px; background-color: lightgray; padding: 5px;">float: left</div>
<div class="test-block  flex" style="margin-top: 50px; background-color: skyblue;">
  margin-top: 50px
</div>


<h2>특정 조건에서 부모 자식간 마진은 병합된다</h2>
<p style="font-size: 14px;">👇자식의 margin-top에서 부모의 margin-top을 분리할 요소가 부모에 없는 경우(border, padding, inline 부분, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_display/Block_formatting_context">블록 형식 맥락</a>이나 clear)</p>
<p>이 아래는 자식 마진이 적용돼 마진이 50px 있다</p>
<div style="background-color: gold;">
  <div style="margin: 50px 10px 0; background-color: skyblue;">
    margin-top: 50px
  </div>
  부모
</div>


<p style="font-size: 14px;">👇자식의 margin-top에서 부모의 margin-top을 분리할 border가 부모에 <strong>있는</strong> 경우</p>
<div style="background-color: gold; border: 1px solid black;">
  <div style="margin: 50px 10px 0; background-color: skyblue;">
    margin-top: 50px
  </div>
  부모(border: 1px solid black)
</div>



<p style="font-size: 14px;">👇부모에 자식의 margin-bottom을 분리할 border, padding, inline 내용, 높이(height, min-height)가 없는 경우</p>
<div style="background-color: gold;">
  부모
  <div style="margin: 0 10px 50px; background-color: skyblue;">
    margin-bottom: 50px
  </div>
</div>
<p>이 위로는 자식 마진이 적용돼 마진이 50px 있다</p>


<p style="font-size: 14px;">👇부모에 자식의 margin-bottom을 분리할 height가 있는 경우</p>
<div style="background-color: gold; height: 130px;">
  부모(height: 130px;)
  <div style="margin: 0 10px 50px; background-color: skyblue;">
    margin-bottom: 50px
  </div>
</div>
<p style="margin: 0;">이 위로는 자식 마진이 작동하지 않아 딱 붙는다.</p>



<h2>border, padding, inline 내용, 높이<sub>(height, min-height)</sub>가 없는 빈 블록의 상하 마진은 스스로 병합된다</h2>
<p>블록 위 (위아래 간격은 30px, 블록에는 margin-top: 30px; margin-bottom: 20px 설정)</p>
<div style="margin-top: 30px; margin-bottom: 20px;"></div>
<p>블록 아래</p>

<h2>좌우 마진은 병합되지 않는다</h2>
<div>
  <div class="test-block  inline-flex  test-block--1">margin-right: 50px</div>
  <div class="test-block  inline-flex  test-block--2">margin-left: 50px;</div>
</div>
              
            
!

CSS

              
                html {
  font-family: Noto Sans, sans-serif;
  max-width: 800px;
  line-height: 1.7;
  box-sizing: border-box;
}

h2 {
  line-height: 1.3;
}

h2:not(:first-child) {
  margin-top: 2em;
  padding-top: 1em;
  border-top: 1px dashed #999;
}

.test-block {
  height: 100px;
  width: 200px;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-family: sans-serif;
}

.flex {
  display: flex;
}

.inline-flex {
  display: inline-flex;
}

.clear {
  clear: both;
}

.test-block--1 {
  background-color: gold;
  color: black;
  margin-right: 50px;
}

.test-block--2 {
  background-color: skyblue;
  color: black;
  margin-left: 50px;
}

              
            
!

JS

              
                
              
            
!
999px

Console