0

I want to make the units rem by the size of browser width that I can use it to make my layout responsive.

Here is my code of js

$(document).ready(function(){
    var rem = function(){ 
        var w = $(window).width() / 640;
        var fs = w * 10 + "px";
        $("html").css("font-size",fs);
        console.log(w*640);
    }
        rem();
     $(window).resize(
     rem
 )});

But the it seems something went wrong

When I load the page the first time

the with of html is 1211 but the value of w*640 is 1228

When I resize the height of browser

But it will be right when I resize the height...

I'm sorry if there something wrong with my code.

I just want to know the reason why.I have always tried $(window) and $("html") to get the with but the result was the same.

Thank you very much for any idea.

Robert
  • 11
  • 1

0 Answers0