Sasha Grievus Sasha Grievus - 2 months ago 6
CSS Question

How to hide all element on html page except one div using css?

I was trying to hide all on an html expect for one

<div>
, as part of a bigger problem.
I have tried...

body * {
display: none;
}
#someTable, #someTable * {
display: block !important;
}


But It doesn't work. What am i doing wrong?

Answer

You can use the pseudo-class ':not()'

<style>
   body *:not(.myDiv) {
        display: none;
    }
</style>


<div>1</div>
<div class="myDiv">2</div>
<div>3</div>