<div class="content">
  <div class="buttons">
  <button class="button" onclick="medium()">medium</button> 
  <button class="button" onclick="thin()">thin</button>  
  <button class="button" onclick="thick()">thick</button> 
  <button class="button" onclick="lengthPxOne()">3px</button>  
  <button class="button" onclick="lengthPx()">10px</button> 
          
  </div>
<div id="border-top-width">Click on the button to change the border-top-width.</div>
  <div class="col"><h2>CSS Code:</h2><p id="code">CSS code</p>
</div>
</div>
body {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.content {
  position: relative;
}

#border-top-width {
  padding: 20px;
  border-style: solid;
  border-width: medium;
  border-top-color: red;
}

.buttons {
  left:-40%;
  position: absolute;
  top:-40px;
  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:450px;
  top:-15px;
}
function medium() {
  document.getElementById("border-top-width").style.borderTopWidth="medium" 
  
  var x = document.getElementById("code");
  if (x.innerHTML === "border-top-width: medium;") {
    x.innerHTML = "border-top-width: medium;";
  } else {
    x.innerHTML = "border-top-width: medium;";
  }
}

function thin() {
  document.getElementById("border-top-width").style.borderTopWidth="thin" 
  
  var x = document.getElementById("code");
  if (x.innerHTML === "border-top-width: thin;") {
    x.innerHTML = "border-top-width: thin;";
  } else {
    x.innerHTML = "border-top-width: thin;";
  }
}

function thick() {
  document.getElementById("border-top-width").style.borderTopWidth="thick" 
  
  var x = document.getElementById("code");
  if (x.innerHTML === "border-top-width: thick;") {
    x.innerHTML = "border-top-width: thick;";
  } else {
    x.innerHTML = "border-top-width: thick;";
  }
}

function lengthPxOne() {
  document.getElementById("border-top-width").style.borderTopWidth="3px" 
  
  var x = document.getElementById("code");
  if (x.innerHTML === "border-top-width: 3px;") {
    x.innerHTML = "border-top-width: 3px;";
  } else {
    x.innerHTML = "border-top-width: 3px;";
  }
}

function lengthPx() {
  document.getElementById("border-top-width").style.borderTopWidth="10px" 
  
  var x = document.getElementById("code");
  if (x.innerHTML === "border-top-width: 10px;") {
    x.innerHTML = "border-top-width: 10px;";
  } else {
    x.innerHTML = "border-top-width: 10px;";
  }
}
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.