.div_box {
border: 1px solid #aaa;
padding: 10px;
display: none;
}
.checkbox:checked + .div_box {
display: block;
}
The CSS code can be used to show/hide a div on checkbox check/uncheck. we are using pseudo-class :checked applied on the checkbox to check whether a checkbox is checked or not and using + keyword we are selecting the next HTML element of the input type checkbox that is a div.
Full Code Example
<input type="checkbox" class="checkbox">
<div class="div_box">
Show me when the checkbox is checked and hide me when the checkbox is unchecked.
</div>
<style>
.div_box {
border: 1px solid #aaa;
padding: 10px;
display: none;
}
.checkbox:checked + .div_box {
display: block;
}
</style>
Output
0 Comments