How to configure an if / or condition so that my design changes depending on the font size of the user's browser?

Defendants: how is the custom font scale literally detected so that it can be used as a variable?

I am trying to create some if / else statements based on scaling the user's font (without scaling the browser) in order to expand the usability of my sites.

The two answers given are workarounds for one case (the described scenario). The originally proposed scenario was not my best choice. However, this can be used, and this is the easiest to understand scenario that I could come up with on the fly.

"If the font size is changed, the value of the offsetWidth / Height properties of elements whose size depends on their text content or CSS size with dimensions related to the font size (em, ex, etc.) will change."

I am trying to figure out a way to create my layout / css by the font size set by the user in his browser settings. For example, in Chrome, if the user set their primary font size to 24 -

Chrome: Wrench> Options> Under the Hood> Change Font and Language Settings> Fonts and Encoding> Font> Change> Font Size = "24".

-

How can I pick up an event? Working with an example ... let's say I have a DIV with a set height of 60px:

<div class="dwarfer" style="height: 60px;">Whoa?</div>

- 9 pt. 24 ( ), ctrl + "mousewheeling down" . :

$divheight = 5px/1em

, , . , , PHP, $divheight .

, :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" » "http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr">
<head>
  <meta http-equiv="Content-Type" content="text/html; » charset=utf-8"> 
  <title>Font Resizer Demo</title>
  <script type="text/javascript" src=" » textresizedetector.js"></script>
</head>
<body>
  <h1>Resize me, now!</h1>
</body>
</html>

<script type="text/javascript" » src="textresizedetector.js"></script>
<script type="text/javascript">
  // <![CDATA[
  /* id of element to check for and insert test SPAN into */
  TextResizeDetector.TARGET_ELEMENT_ID = 'header';
  /* function to call once TextResizeDetector was initialized */
  TextResizeDetector.USER_INIT_FUNC = init;
  // ]]>
</script>

http://www.alistapart.com/articles/fontresizing/.

, $divheight CSS :

/* CSS */
<?php
  //variables
  $divheight = 5px/1em
  //end variables

  //styles
  echo '.dwarfer{' . "\n" . 'height:' . $divheight; . "\n" . '}'
  //end styles
?>

! !

+3
2

css, px pt. em ex.

em  1em is equal to the current font size. 2em means 2 times the size of the current font.
      E.g., if an element is displayed with a font of 12 pt, then '2em' is 24 pt. The 'em'
      is a very useful unit in CSS, since it can adapt automatically to the font that the
      reader uses

ex  one ex is the x-height of a font (x-height is usually about half the font-size)
+3

em, px. em , , , , div - :

<div class="dwarfer" style="height: 1.2em;line-height:1.2em;">Whoa?</div>

javascript. div , - , div , , div .

, .


em:

em , px. font-size. :

<div style="font-size: 2em;">Twice as big</div>

, div, , .

+1

Source: https://habr.com/ru/post/1764622/


All Articles