<div class="content">
<div class="buttons">
<button class="button" onclick="functionContentBox()">content-box</button>
<button class="button" onclick="functionBorderBox()">border-box</button>
</div>
<div id="box-container">
<div class="box1" id="box1">This is BOX1.</div>
<div class="box2" id="box2">This is BOX2.</div>
<div style="clear:both;"></div>
</div>
<div class="col"><h2>CSS Code:</h2><p id="code">CSS code</p>
</div>
body {
display: flex;
height: 100vh;
justify-content: center;
align-items: center;
}
.content {
top:-50px;
position: relative;
left:-70px;
}
#box-container {
width: 300px;
border: 3px solid #333;
position: fixed;
}
#box1, #box2 {
width: 150px;
border: 3px solid #0a9396;
float: left;
padding: 10px;
}
.buttons {
margin-left:-145px;
top:60px;
position: relative;
}
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: relative;
font-weight: bold;
font-size:15px;
width: 100%;
left:345px;
top:-20px;
}
function functionContentBox() {
document.getElementById("box1").style.boxSizing = "content-box";
document.getElementById("box2").style.boxSizing = "content-box";
var x = document.getElementById("code");
if (x.innerHTML === "box-sizing: content-box;") {
x.innerHTML = "box-sizing: content-box;";
} else {
x.innerHTML = "box-sizing: content-box;";
}
}
function functionBorderBox() {
document.getElementById("box1").style.boxSizing = "border-box";
document.getElementById("box2").style.boxSizing = "border-box";
var x = document.getElementById("code");
if (x.innerHTML === "box-sizing: border-box;") {
x.innerHTML = "box-sizing: border-box;";
} else {
x.innerHTML = "box-sizing: border-box;";
}
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.