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="level">
  <h1>水平居中</h1>

  <div class="wrapper wrapper1">
    <span>行内,text-align: center;</span>
  </div>

  <div class="wrapper wrapper2">
    <div>
      块元素
      <p>(定宽度)</p>
      <p>margin: 0 auto</p>
    </div>
  </div>

  <div class="wrapper wrapper3">
    <div>块元素(不定宽度)</div>
  </div>

  <div class="wrapper wrapper4">
    <div>
      块元素
      <p>flex实现</p>
      <p>(定不定宽度可以)</p>
    </div>
  </div>
</div>

<div class="vertical">
  <h1>垂直居中</h1>

  <div class="wrapper wrapper5">
    <span>单行的行内元素,设置行高</span>
  </div>

  <div class="wrapper wrapper6">
    <span>多行的行内元素,多行的行内元素,多行的行内元素,多行的行内元素,多行的行内元素,多行的行内元素</span>
  </div>
  <br />

  <div class="wrapper wrapper7">
    <div>块级元素(定高度)</div>
  </div>

  <div class="wrapper wrapper8">
    <div>
      块级元素
      <p>flex实现</p>
      <p>(定不定高度可以)</p>
    </div>
  </div>
</div>

<div class="levelVertical">
  <h1>水平垂直居中</h1>

  <div class="wrapper wrapper9">
    <div>
      块级元素
      <p>已知宽高</p>
    </div>
  </div>

  <div class="wrapper wrapper10">
    <div>
      块级元素
      <p>已知宽高</p>
    </div>
  </div>

  <div class="wrapper wrapper11">
    <div>
      块级元素
      <p>未知宽高</p>
    </div>
  </div>

  <div class="wrapper wrapper12">
    <div>
      块级元素
      <p>flex实现</p>
      <p>未知宽高</p>
    </div>
  </div>
</div>
              
            
!

CSS

              
                .level,
.vertical,
.levelVertical {
  float: left;
  margin: 10px;
  font-size: 15px;
}
h1 {
  text-align: center;
}
.wrapper {
  width: 240px;
  height: 150px;
  background: #eee;
  margin-bottom: 20px;
}
.wrapper > div {
  background: coral;
}

.wrapper1 {
  text-align: center;
}

.wrapper2 div {
  width: 100px;
  margin: 0 auto;
}

.wrapper3 {
  text-align: center;
}
.wrapper3 div {
  display: inline;
}

.wrapper4 {
  display: flex;
  justify-content: center;
}

.wrapper5 {
  line-height: 150px;
}

.wrapper6 {
  display: table-cell;
  vertical-align: middle;
}

.wrapper7 {
  position: relative;
}
.wrapper7 div {
  height: 100px;
  position: absolute;
  top: 50%;
  margin-top: -50px;
}

.wrapper8 {
  display: flex;
  align-items: center;
}

.wrapper9 {
  position: relative;
}
.wrapper9 div {
  width: 100px;
  height: 100px;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: auto;
}

.wrapper10 {
  position: relative;
}
.wrapper10 div {
  width: 100px;
  height: 100px;
  position: absolute;
  left: 50%;
  top: 50%;
  margin-left: -50px;
  margin-top: -50px;
}

.wrapper11 {
  position: relative;
}
.wrapper11 div {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translateX(-50%) translateY(-50%);
}

.wrapper12 {
  display: flex;
  justify-content: center;
  align-items: center;
}

              
            
!

JS

              
                
              
            
!
999px

Console