<div class="form">
  <label for="display">display:</label>
  <select name="display" id="display">
    <option value="block">block</option>
    <option value="inline">inline</option>
    <option value="inline-block">inline-block</option>
    <option value="flex">flex</option>
    <option value="inline-flex">inline-flex</option>
    <option value="grid">grid</option>
    <option value="inline-grid">inline-grid</option>
  </select>
</div>
<div class="wrapper">
  <div class="box"></div>
  <pre class="code">
    <span></span>
    <span></span>
  </pre>
</div>
@import url("https://fonts.googleapis.com/css?family=Gochi+Hand");

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

body {
  margin: 0;
  padding: 0;
  background-color: #291642;
  font-family: "Gochi Hand", sans-serif;
  color: #fff;
  font-size: 130%;
  letter-spacing: 0.1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100vw;
  min-height: 100vh;
}

.wrapper {
  width: 50vw;
  height: 50vh;
  min-width: 200px;
  border: 1px dashed #fff;
  overflow: hidden;
  resize: horizontal;
  position: relative;
}

.box {
  min-height: 100px;
  background-color: #f36;
  margin: 2px 0;
}

.box2 {
  width: 100%;
  background-color: hsl(0.5turn, 90%, 30%);
}

.code {
  position: absolute;
  bottom: 10px;
  left: 10px;
  right: 10px;
  text-align: center;
  white-space: nowrap;
  span {
    display: block;
    margin: 5px;
  }
}

.form {
  margin-bottom: 5px;
}
View Compiled
const wrapper = document.querySelector(".wrapper");
const code = document.querySelectorAll(".code > span");
const select = document.querySelector("#display");
const box = document.querySelector(".box");

const objResizeObserver = new ResizeObserver(function(entries) {
  const entry = entries[0];
  let cr = entry.contentRect;
  const width = parseInt(cr.width);
  code[0].textContent = `div.wrapper的width: ${width}px`;
  const boxWidth = box.offsetWidth;
  const content = `div.box的width: ${boxWidth}px`;
  code[1].textContent = content;
});

objResizeObserver.observe(wrapper);

select.addEventListener("change", e => {
  wrapper.style.display = e.target.value;
  const boxWidth = box.offsetWidth;
  const content = `div.box的width: ${boxWidth}px`;
  code[1].textContent = content;
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.