change text-font size of whole page content

前端 未结 5 1116
北海茫月
北海茫月 2020-12-10 15:49

is there a way in javascript/css that i can change text size of all the labels, headings, paragraphs etc on a single click and without explicitly getting element\'s id and t

5条回答
  •  情书的邮戳
    2020-12-10 16:41

    I'd recommend using ems as a measure for setting font sizes. That way, with 1 tag, you can adjust the font sizes of every element relatively, instead of specifying specific sizes. Example:

    body {
      font-size: 1em;
    }
    
    h1 {
      font-size: 1.5em;
    }
    
    h2 {
      font-size: 1.3em;
    }
    
    p.large {
      font-size: 1.2em;
    }
    

    Then you could apply a class to the body, like so

    body.enlarged {
      font-size: 1.3em;
    }
    

    Which would scale the font size of all elements respectively. The javascript code would go something like this:

    document.body.classList.add('enlarged');
    

    Demo here: http://jsfiddle.net/bW9fM/1/

提交回复
热议问题