Media query combined with rem layout in CSS3 to adapt to mobile screens

Media query combined with rem layout in CSS3 to adapt to mobile screens

CSS3 syntax: (1rem = 100px for a 750px design)

@media only screen and (min-width: 320px) and (max-width: 479px) {
    html {
        font-size: 42.67px !important;
    }
}
@media only screen and (min-width: 480px) and (max-width: 639px) {
    html {
        font-size: 64px !important;
    }
}
@media only screen and (min-width: 640px) and (max-width: 749px) {
    html {
        font-size: 85.34px !important;
    }
}
@media only screen and (min-width: 750px) and (max-width: 959px) {
    html {
        font-size: 100px !important;
    }
}
@media only screen and (min-width: 960px) and (max-width: 1241px) {
    html {
        font-size: 128px !important;
    }
}
@media only screen and (min-width: 1242px) {
    html {
        font-size: 165.6px !important;
    }
}

js control

(zepto/jQuery) (1rem = 100px for a 750px design)
function setFont() {
    let window_width = window.innerWidth;
    let font_size = parseFloat(window_width / 3.75);
    $('html').css('font-size', font_size);
}

$(window).on('resize', function () {
    setFont();
});

Summarize

The above is what I introduced to you about media queries in CSS3 combined with rem layout to adapt to mobile phone screens. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time!

<<:  Docker solution for logging in without root privileges

>>:  Detailed explanation of MySQL backup process using Xtrabackup

Recommend

JS realizes the effect of picture waterfall flow

This article shares the specific code of JS to re...

Example code for implementing raindrop animation effect with CSS

Glass Windows What we are going to achieve today ...

The difference between div and table in speed, loading, web application, etc.

1: Differences in speed and loading methods The di...

HTML mouse css control

Generally speaking, the mouse is displayed as an u...

js method to delete a field in an object

This article mainly introduces the implementation...

How to create a my.ini file in the MySQL 5.7.19 installation directory

In the previous article, I introduced the detaile...

How to select all child elements and add styles to them in CSS

method: Take less in the actual project as an exa...

MySQL index usage instructions (single-column index and multi-column index)

1. Single column index Choosing which columns to ...

Detailed explanation of JavaScript's built-in objects Math and strings

Table of contents Math Objects Common properties ...

How to implement scheduled backup of MySQL in Linux

In actual projects, the database needs to be back...

Install mysql5.7.17 using RPM under Linux

The installation method of MySQL5.7 rpm under Lin...

How to use JavaScript to determine several common browsers through userAgent

Preface Usually when making h5 pages, you need to...

Nginx local directory mapping implementation code example

Sometimes you need to access some static resource...