HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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>
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;
}
Also see: Tab Triggers