Pen Settings

HTML

CSS

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

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

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.

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

              
                <div class="wrapper">
<h2>範例一、使用 float 指令導致版面跑位</h2>
   <p>以下是傳統的區塊浮動設定方式,區塊單純的使用 float:left 屬性,讓黃色的 container 區塊被先前的 2 個黑框 item 區塊重疊。</p>
  <div class="item item-floatleft">設定 float: left 會與其他元素重疊</div>
  <div class="item item-floatleft">設定 float: left 會與其他元素重疊</div>
  <div class="container container1">
  被重疊到的元素
</div>
  


<h2 class="clear">範例二、使用 clear 指令修正版面重疊版面跑位</h2>
<div>
  以下將範例一中被重疊的黃色區塊,在它的 CSS 中多加了 clear 屬性來修正被黑框元素重疊到的窘境
</div>
<div class="item item-floatleft">設定 float: left 需要靠 clear 元素修正重疊的窘境</div>
<div class="item item-floatleft">設定 float: left 需要靠 clear 元素修正重疊的窘境</div>
  
<div class="container container2">因為黃色區塊的 CSS 多設定了 clear 屬性,所以才沒有被設定為「float:left」的黑框元素重疊到</div>
  
<h2>範例三、使用 display: inline-block 取代 float 指令</h2>

<p>以下範例為黑框區塊的 CSS 中使用「display: inline-block」取代 float 屬性,這樣黃色區塊的 CSS 就不用多增加 clear 屬性,也不會被重疊到。</p>


  <div class="item item-inlineblock">黑框區塊使用「display: inline-block」取代 float</div>
  <div class="container container1">只要黑框區塊使用「display: inline-block」取代 float,黃色區塊不用設定 clear 屬性也可以不被重疊到。
</div>
  
</div>
              
            
!

CSS

              
                .item {
  height: 100px;
  width: 120px;
  border: 5px solid #000;
  background-color: ;
  margin: 10px;
  border-radius: 5px;
  padding: 10px;
}

.item-floatleft {
  float: left;
}

.item-inlineblock {
  display: inline-block;
  padding: 10px;
}

.container {
  border: 2px solid yellow;
  border-radius: 5px;
  background-color: yellow;
  width: 400px;
  padding: 5px;
  margin: 10px;
}


.container2 {
  clear: both;
  content: "";
  display: block;
  margin: 10px;
}

.container3 {
  display: inline-block;
}

h2 {
  padding: 2em 0 0 0;
}

.clear {
  clear: both;
}

body {
  font: 16px 微軟正黑體, sans-serif;
}

.wrapper {
  max-width: 600px;
  margin: 40px auto;
}
              
            
!

JS

              
                
              
            
!
999px

Console