Hide A Div With CSS Only

when the button is inside the div that needs to hide.

Short answer: No, you can't achieve this when the button is inside the element. Thanks Joseph Marikle

However, you can achieve this when the button is outside the div.

#hide {
  display: none;
}
label {
  cursor: pointer;
  text-decoration: underline;
}
#hide:checked ~ #randomDiv {
  display: none;
}
<input type="checkbox" id="hide" />


<div id="randomDiv">
  This is a div
  <label for="hide">Hide div</label>
</div>

Tags:

Html

Css