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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 id="app" class="container"></div>
              
            
!

CSS

              
                 @import 'https://fonts.googleapis.com/css?family=Share+Tech+Mono';

@import 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css';

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
    width: 100vw;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/1376484/jess-harding-lqT6NAmTaiY-unsplash.jpg'),radial-gradient(#28a3dd, #0d7751);
    background-size: cover;
    background-position: center;
    font-family: "Share Tech Mono", monospace;
    font-size: 2rem;
    background-blend-mode: multiply,screen, overlay;
}


#app {
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: #fff;
  border-radius: 5px;
  padding: 2vh;
}

.house {
  position: relative;
  height: 380px;
  width: 400px;
  margin: 3vh;
}

img {
  position: absolute;
}

.roof {
  left: 0;
  top: 0;
  border-width: 0;
}

.chimney {
  left: 255px;
}

.wall {
  left: 5px;
  top: 48px;
}

.window {
  left: 200px;
  top: 182px;
}

.door {
  left: -25px;
  top: 182px;
}
              
            
!

JS

              
                // 创建房顶组件

const Roof = ({color, roofSrc}) => {
  return <img src={roofSrc} className="roof" style={{background: `${color}`}} />
}

// 创建墙
const Wall = ({wallSrc}) => {
  return <img src={wallSrc} className='wall' />;
}

// 创建窗户
const Window = ({windowSrc}) => {
  return <img src={windowSrc} className='window' />;
}

// 创建门
const Door = ({doorSrc}) => {
  return <img src={ doorSrc } className='door' />;
}

// 创建房子
const House = (props) => {
  return (
    <div className='house'>      
        <Roof color={props.color} roofSrc={props.roofSrc} />
        <Wall wallSrc={props.wallSrc} />
        <Window windowSrc={props.windowSrc} />
        <Door doorSrc={props.doorSrc} />
    </div>
  )
}


const App = () => {
  return (
      <House 
        color="blue"
        roofSrc="https://cdn.glitch.com/1fb3273a-81cb-45bc-acbd-555546cb098f%2Froof.png?1515785259159"
        wallSrc="https://cdn.glitch.com/1fb3273a-81cb-45bc-acbd-555546cb098f%2Fwall.png?1501113882297"
        windowSrc="https://cdn.glitch.com/1fb3273a-81cb-45bc-acbd-555546cb098f%2Fwindow.png?1501113882112"
        doorSrc="https://cdn.glitch.com/1fb3273a-81cb-45bc-acbd-555546cb098f%2Fdoor_close.png?1501113881433"
        />
  )
}

ReactDOM.render(<App />, document.getElementById('app'));
              
            
!
999px

Console