<aside>click anywhere to toggle containment</aside>

<main>
  <p id="desc">contain: none;</p>
  <div></div>
  <div></div>
  <div></div>
</main>
@import url('https://fonts.googleapis.com/css?family=Open+Sans&display=swap');

html {
  font-family: 'Open Sans', sans-serif;
  height: 100%;
  overflow: hidden;
}
body {
  align-items: center;
  background-color: #1d1e22;
  color: white;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  height: 100%;
  justify-content: center;
  margin: 0;
  padding: 0;
}

aside {
  left: 0;
  margin: 20px 0;
  position: fixed;
  text-align: center;
  top: 50px;
  width: 100%;
}

main {
  background-color: #333;
  border: 3px solid rebeccapurple;
  contain: none;
  margin: 20px auto;
  width: 300px;
  
  &.size {
    contain: size;
    height: 100px;
  }
  
  p {
    margin: 5px;
    text-align: center;
  }
  
  div {
    border: 1px solid red;
    height: 100px;
    margin: 10px;
  }
}
View Compiled
const main = document.querySelector('main');
const desc = document.querySelector('#desc');

document.body.addEventListener('click', function () {
  main.classList.toggle('size');
  
  desc.innerText = main.classList.contains('size') ? 'contain: size;' : 'contain: none;';
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.