<div id="app" class="container"></div>
 @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;
}
View Compiled
// 创建房顶组件

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

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

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

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

// 创建房子
const House = ({color, roof, wall, window, door}) => {
  return (
    <div className='house'>      
        <Roof color={color} roof={roof} />
        <Wall wall={wall} />
        <Window window={window} />
        <Door door={door} />
    </div>
  )
}


const App = () => {
  const houses = {
    color: 'orange',
    roof: 'https://cdn.glitch.com/1fb3273a-81cb-45bc-acbd-555546cb098f%2Froof.png?1515785259159',
    wall: 'https://cdn.glitch.com/1fb3273a-81cb-45bc-acbd-555546cb098f%2Fwall.png?1501113882297',
    window: 'https://cdn.glitch.com/1fb3273a-81cb-45bc-acbd-555546cb098f%2Fwindow.png?1501113882112',
    door: 'https://cdn.glitch.com/1fb3273a-81cb-45bc-acbd-555546cb098f%2Fdoor_close.png?1501113881433'
  }
  return (
      <>
      <House {...houses} />
      <House 
        {...houses}
        color="salmon"
        door="https://cdn.glitch.com/1fb3273a-81cb-45bc-acbd-555546cb098f%2Fdoor_open.png?1501113882121"
        />
      </>
  )
}

ReactDOM.render(<App />, document.getElementById('app'));
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/react/16.10.2/umd/react.production.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.10.2/umd/react-dom.production.min.js