<div class="content">
  
  <div class="buttons">
        <button class="button" onclick="borderBox()">border-box</button>
  <button class="button" onclick="paddingBox()">padding-box</button>  
    <button class="button" onclick="contentBox()">content-box</button>  
  </div>
  
<div id="text-container">
  <div id="text" class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</div>
  </div>
  
     <div class="col"><h2>CSS Code:</h2><p id="code">CSS code</p>
</div>
</div>
body {
  display: flex;
  justify-content: center;
  height: 100vh;
  align-items: center;
  overflow: hidden;
}

.content {
  position: relative;
}

#text-container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.text {
  text-align: justify;
  width: 25%;
  border: 5px dashed;
  background-color: #fed9b7;
  padding:20px;
  background-clip: border-box;
}

.buttons {
  left:25%;
  top:0;
  position: absolute;
  z-index:1;
}

button {
  background-color: #333;
  color: white;
  border: none;
  display: block;
  padding:5px;
  width: 100px;
  margin:5px;
  transition: .2s;
  font-weight: bold;
}

button:hover {
  background-color: white;
  color: #333;
}

.col {
  position: absolute;
  font-weight: bold;
  font-size:15px;
  width: 100%;
  left:70%;
  top:0;
}

@media only screen and (max-width: 600px) {
  .text {
    font-size:10px;
  }
}
function borderBox() {
  document.getElementById("text").style.backgroundClip="border-box" 
  
  var x = document.getElementById("code");
  if (x.innerHTML === "background-clip: border-box;") {
    x.innerHTML = "background-clip: border-box;";
  } else {
    x.innerHTML = "background-clip: border-box;";
  }
}

function paddingBox() {
  document.getElementById("text").style.backgroundClip="padding-box" 
  
  var x = document.getElementById("code");
  if (x.innerHTML === "background-clip: padding-box;") {
    x.innerHTML = "background-clip: padding-box;";
  } else {
    x.innerHTML = "background-clip: padding-box;";
  }
}

function contentBox() {
  document.getElementById("text").style.backgroundClip = "content-box";
  
  var x = document.getElementById("code");
  if (x.innerHTML === "background-clip: content-box;") {
    x.innerHTML = "background-clip: content-box;";
  } else {
    x.innerHTML = "background-clip: content-box;";
  }
}
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.