3

I want to hide all the elements in some screen resolution and just show the wanted element to be visible:

For instance:

*{
    display: none;
}
#block{
    display: block !important;
}

But this won't override the display property anymore. demo

Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231

3 Answers3

8

* targets all elements within the document, including html and body as well. That's why the content is still hidden - verify that.

If you want to select all elements within the <body> you should do that as follows:

body * {
    display: none;
}

#block {
    display: block;
}
<div id="block">block</div>
Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164
  • @Paulie_D indeed! I just focused on the selector. – Hashem Qolami Oct 16 '14 at 12:21
  • 1
    This worked out fine for me when I wanted to print just the chart.js chart on a page; which i answered via this question: http://stackoverflow.com/questions/37192878/chart-from-chart-js-to-pdf (printing just a chart using media-print). – Rick Hellewell Apr 27 '17 at 04:17
1

Because body and html are included in the universal selector *, which has the display: none; rule.

http://jsfiddle.net/nk8np9vo/6/

Lorenzo Marcon
  • 8,029
  • 5
  • 38
  • 63
  • 1
    @C-linkNepal - [and you don't need !important](http://jsfiddle.net/yy06ra96/1/) as the style will be overwritten. – misterManSam Oct 16 '14 at 12:20
1

If you open the target frame with your favourite DOM inspector you'll see that <body> remains hidden:

Firebug

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • @misterManSam - There're excellent explanations so far in other answers. Mine just provides a hint on how to diagnose this kind of issues. – Álvaro González Oct 16 '14 at 12:25