1

In pseudo-code, something like this:

div:zoom(2){
    color:red;
}

which should set color of all the divs to red when the zoom is 2x.

Is it possible with pure CSS?

nicael
  • 18,550
  • 13
  • 57
  • 90
  • To access information that is either outside the DOM tree or difficult to access in the DOM tree, you go to use pseudo classes and pseudo elements. think of it as a compliment to pure CSS, which cannot be expressed by using normal selector – Tawfik Khalifeh Jan 04 '15 at 18:37
  • 1
    What do you mean by `zoom`? Do you mean a user zoom triggered by the OS? By the browser? Or do you mean the actual `zoom` property within CSS? – helloanselm Jan 04 '15 at 18:44
  • Assuming you mean browser zoom, I don't think CSS has browser zoom selector. [Detecting browser zoom is not trivial](https://stackoverflow.com/questions/1713771/how-to-detect-page-zoom-level-in-all-modern-browsers). You might be better off trying to make your content work at different zoom levels. – Alexander O'Mara Jan 04 '15 at 18:44
  • @hello by zoom I mean when user increases the size of the window content. – nicael Jan 04 '15 at 18:45

1 Answers1

1

You can’t really detect if a user zooms a page. This is due to these restrictions:

  • CSS is not able to get such information except via Media Queries. But even in Media Queries Level 4 (not implemented yet by any browser) there’s no zoom level detection.
  • Browser zoom can be two ways: font-size zoom or page zoom.

For the latter, with JavaScript there are some possibilities to detect the zoom level. You better shouldn’t rely on it and I’d consider twice if to include such a hacky script into a codebase.

See this answer on Stack Overlow: https://stackoverflow.com/a/5078596/3689130
See this Github repository: https://github.com/yonran/detect-zoom

Community
  • 1
  • 1
helloanselm
  • 329
  • 2
  • 12
  • I ask about page zoom. So not possible? Ok. Thanks for the info! – nicael Jan 04 '15 at 18:57
  • As said, it’s somehow possible (as the github repo does) but it’s a hacky solution and I wouldn’t use it for production sites/applications. :) – helloanselm Jan 06 '15 at 08:53