<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;
}
// House所需的素材
const IMAGES = {
  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_open: 'https://cdn.glitch.com/1fb3273a-81cb-45bc-acbd-555546cb098f%2Fdoor_open.png?1501113882121',
  door_closed: 'https://cdn.glitch.com/1fb3273a-81cb-45bc-acbd-555546cb098f%2Fdoor_close.png?1501113881433',
  cat_sleeping: 'https://cdn.glitch.com/1fb3273a-81cb-45bc-acbd-555546cb098f%2Fcat_sleeping.png?1515785234959',
  cat_awake: 'https://cdn.glitch.com/1fb3273a-81cb-45bc-acbd-555546cb098f%2Fcat_standing.png?1515785235095',
}

// 创建房顶组件

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

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

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

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

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


const App = () => {
  return (
    <>
      <House color="blue" />
      <House color="red" />
      <House color="salmon" />
    </>  
  )
}

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