0

I am working on a project where I need to change font style and size according to user need like if the user's devices have large font-size than font-size of web pages also large.

For example, your android or ios device has base fonts-size like below

main heading - 18px secondary heading - 16px content - 14px

and your web main page Font-size is

main heading - 16px secondary heading - 18px content - 12px

Now I want to detect the android or ios device font-size to change my web page font size.

2 Answers2

0

(continuation from comments above).

var div = document.getElementsByTagName('body')[0]; // this will set the body tag as variable
// this taken from here: https://stackoverflow.com/a/7444724/6525081
function css( element, property ) { 
    return window.getComputedStyle( element, null ).getPropertyValue( property );
}
alert( css( div, 'font-size' ) );

Read more about getComputedStyle here

You can check similar fiddle here

Hope that helps.

A. Meshu
  • 4,053
  • 2
  • 20
  • 34
  • Yes, I have tried this. This code will get the font-size of particular div or element, I am asking about my device native font size. – Dharmesh Mertwal Jul 19 '19 at 04:00
  • Using this code will get you the initial font-size that all elements will render from (the body of the document - as the browser display it). Once you have it you can decide what to do with it. What is your goal? If it will be 16px - than what? – A. Meshu Jul 19 '19 at 18:10
-3

you should use media queries, this command is for you to define specific styles for certain screen sizes, follow a tutorial on how to use

Example:

@media only screen and (max-width: 600px) {
  body {
    background-color: lightblue;
  }
}

Complete tutorial here

in case you want to change the source according to the size of the device source use the rem

it is a measure that takes as a base the size of the font configured in the browser

Example:

div{
   font-size: 1rem
}

Here's the rem tutorial

Lucas
  • 275
  • 8
  • 37