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

              
                <div id="root"></div>
              
            
!

CSS

              
                body {
  padding: 2rem;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue",
    "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC",
    "WenQuanYi Micro Hei", sans-serif;
  font-size: 14px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

h2 {
  font-weight: 300;
}

.Demo {
  margin: 0 auto;
  max-width: 1010px;
}

.Demo .Mdi {
  background: rgba(0, 0, 0, .1);
}

.LineBox {
  position: relative;
  font-size: 100px;
  white-space: nowrap;
}

.LineBox .content {
  display: inline-block;
  width: 100%;
  margin-right: -100%;
  text-align: center;
}

.LineBox .line {
  position: relative;
  z-index: 2;
  display: inline-block;
  width: 100%;
  margin-right: -100%;
  border-top: 1px dashed;
  opacity: 0.5;
}

.LineBox .top {
  vertical-align: top;
  border-color: gray;
}

.LineBox .textTop {
  vertical-align: text-top;
  border-color: lightgray;
}

.LineBox .middle {
  vertical-align: middle;
  border-color: green;
}

.LineBox .baseline {
  vertical-align: baseline;
  border-color: red;
}

.LineBox .textBottom {
  vertical-align: text-bottom;
  border-color: lightgray;
}

.LineBox .bottom {
  vertical-align: bottom;
  border-color: gray;
}

.LineBox .cap {
  /* 假想的 cap line(平均高度),不一定准确(不同字体不同) */
  vertical-align: 0.7em;
  border-color: lightsteelblue;
}

              
            
!

JS

              
                // Demo 4: strut hack
const ZWSP = '\u200b' /* ZWSP(zero-width space) */

const InlineBlockStrutHackIcon = ({size, width, height, ...props}) => (
  <span
    style={{
      position: 'relative',
      display: 'inline-block',
      lineHeight: size || height, // 使元素高度等于字体大小
      width: size || width, // 占住横向空间
    }}
  >
    {ZWSP}
    <Icons.Favorite
      width={size || width}
      height={size || height}
      style={{position: 'absolute', left: 0, top: 0}}
    />
  </span>
)

const InlineFlexStrutHackIcon = props => (
  <span
    style={{
      display: 'inline-flex',
      alignItems: 'center',
    }}
  >
    {ZWSP}
    <Icons.Favorite {...props} />
  </span>
)

const Demo = () => (
  <div className="Demo">
    <h2>inline-block + strut hack</h2>
    <LineBox>
      <InlineBlockStrutHackIcon size=".6em" />&nbsp;
      <InlineBlockStrutHackIcon size="1em" />&nbsp;
      <InlineBlockStrutHackIcon size="1.2em" />
      喜欢 Like
    </LineBox>

    <h2>inline-flex + strut hack</h2>
    <LineBox>
      <InlineFlexStrutHackIcon size=".6em" />&nbsp;
      <InlineFlexStrutHackIcon size="1em" />&nbsp;
      <InlineFlexStrutHackIcon size="1.2em" />
      喜欢 Like
    </LineBox>

    <h2>flex container without hacks</h2>
    <LineBox>
      <span
        style={{
          display: 'inline-flex',
          alignItems: 'center',
          verticalAlign: 'top',
        }}
      >
        <Icons.Favorite size=".6em" />&nbsp;
        <Icons.Favorite size="1em" />&nbsp;
        <Icons.Favorite size="1.2em" />
        喜欢 Like
      </span>
    </LineBox>
  </div>
)

const Debugger = ({size}) => (
  <span
    style={{
      display: 'inline-block',
      lineHeight: 1.2,
      background: 'lightsalmon',
    }}
  >
    i
  </span>
)

const LineBox = ({children, ...props}) => (
  <div draggable className="LineBox" {...props}>
    <span className="content">{children}</span>
    <span className="line top" />
    <span className="line textTop" />
    <span className="line cap" />
    <span className="line middle" />
    <span className="line baseline" />
    <span className="line textBottom" />
    <span className="line bottom" />
  </div>
)

// 完整封装见:http://ambar.li/reiconify/md.icons/
const Icon = ({size, ...props}) => (
  <svg {...props} {...size && {width: size, height: size}} />
)

Icon.defaultProps = {
  width: '1.2em',
  height: '1.2em',
  fill: 'currentColor',
  viewBox: '0 0 24 24',
}

const Icons = {
  AccessAlarm: props => (
    <Icon className="Mdi Mdi--AccessAlarm" {...props}>
      <path d="M22 5.72l-4.6-3.86-1.29 1.53 4.6 3.86L22 5.72zM7.88 3.39L6.6 1.86 2 5.71l1.29 1.53 4.59-3.85zM12.5 8H11v6l4.75 2.85.75-1.23-4-2.37V8zM12 4c-4.97 0-9 4.03-9 9s4.02 9 9 9a9 9 0 0 0 0-18zm0 16c-3.87 0-7-3.13-7-7s3.13-7 7-7 7 3.13 7 7-3.13 7-7 7z" />
    </Icon>
  ),

  Favorite: props => (
    <Icon className="Mdi Mdi--Favorite" {...props}>
      <path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z" />
    </Icon>
  ),

  Copyright: props => (
    <Icon className="Mdi Mdi--Copyright" {...props}>
      <path d="M10.08 10.86c.05-.33.16-.62.3-.87s.34-.46.59-.62c.24-.15.54-.22.91-.23.23.01.44.05.63.13.2.09.38.21.52.36s.25.33.34.53.13.42.14.64h1.79c-.02-.47-.11-.9-.28-1.29s-.4-.73-.7-1.01-.66-.5-1.08-.66-.88-.23-1.39-.23c-.65 0-1.22.11-1.7.34s-.88.53-1.2.92-.56.84-.71 1.36S8 11.29 8 11.87v.27c0 .58.08 1.12.23 1.64s.39.97.71 1.35.72.69 1.2.91 1.05.34 1.7.34c.47 0 .91-.08 1.32-.23s.77-.36 1.08-.63.56-.58.74-.94.29-.74.3-1.15h-1.79c-.01.21-.06.4-.15.58s-.21.33-.36.46-.32.23-.52.3c-.19.07-.39.09-.6.1-.36-.01-.66-.08-.89-.23-.25-.16-.45-.37-.59-.62s-.25-.55-.3-.88-.08-.67-.08-1v-.27c0-.35.03-.68.08-1.01zM12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z" />
    </Icon>
  ),
}

ReactDOM.render(<Demo />, document.getElementById('root'))

              
            
!
999px

Console