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

Modify the maximum number of mysql connections and configuration files in docker

1. Find the mysql image docker ps 2. Enter the mi...

Analysis of pitfalls in rounding operation of ROUND function in MySQL

This article uses examples to illustrate the pitf...

Explanation of the steps for Tomcat to support https access

How to make tomcat support https access step: (1)...

JavaScript Dom Object Operations

Table of contents 1. Core 1. Get the Dom node 2. ...

Analysis and solution of the problem that MySQL instance cannot be started

Table of contents Preface Scenario Analysis Summa...

Example of how to optimize MySQL insert performance

MySQL Performance Optimization MySQL performance ...

Solution to Ubuntu cannot connect to the network

Effective solution for Ubuntu in virtual machine ...

Share CSS writing standards and order [recommended for everyone to use]

CSS writing order 1. Position attributes (positio...

Discuss the development trend of Baidu Encyclopedia UI

<br />The official version of Baidu Encyclop...

Examples of vertical grid and progressive line spacing

New Questions Come and go in a hurry. It has been...

Detailed process of Vue front-end packaging

Table of contents 1. Add packaging command 2. Run...

WeChat applet custom scroll-view example code

Mini Program Custom Scroll-View Scroll Bar Withou...