<div class="wrapper">
<div class="box"></div>
<div class="box box2"></div>
<pre class="code"></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;
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;
}
View Compiled
const wrapper = document.querySelector(".wrapper");
const code = document.querySelector(".code");
const objResizeObserver = new ResizeObserver(function(entries) {
const entry = entries[0];
let cr = entry.contentRect;
const width = cr.width;
code.textContent = `width: ${width}px`;
});
objResizeObserver.observe(wrapper);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.