<p>This is a paragraph element directly in the body element. Theborder is red by default, since that's what the stylesheet declares for paragraphs, but it will be black when <code>unset</code> is enabled because that is the <code>initial</code> value set by the browser.</p>
<div>
This is text inside a div element that has a green border because the stylesheet says all divs should have a green border.
<p>This paragraph has a green border by default, because that's what is inherited from the div element. With <code>unset</code>, the border will become black because, again, that's what the <code>initial</code> value is.</p>
</div>
<button id="toggle">Toggle Unset</button>
body {
margin: 0 auto;
max-width: 80%;
}
div {
border: 5px solid green;
padding: 0.5rem;
}
p {
border: 5px solid red;
padding: 0.5rem;
}
div p {
border-color: inherit;
}
.unset {
border-color: unset;
}
button {
background-image: linear-gradient(to top left, #ff8a00, #e52e71);
border: none;
border-radius: 8px;
color: #fff;
cursor: pointer;
font-weight: 800;
margin-top: 1rem;
padding: 1rem 1.5rem;
}
button:hover {
background-image: linear-gradient(to top left, #ff8a00 30%, #e52e71);
transform: translateY(1px);
}
button:active {
transform: translateY(2px);
}
$("#toggle").click(function () {
$("p").toggleClass("unset");
});
This Pen doesn't use any external CSS resources.