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

How to configure Linux to use LDAP user authentication

I am using LDAP user management implemented in Ce...

Instructions for using MySQL isolation Read View

Which historical version can the current transact...

Summary of DTD usage in HTML

DTD is a set of grammatical rules for markup. It i...

Bug of Chinese input garbled characters in flex program Firefox

Chinese characters cannot be input in lower versio...

How to set up a shared folder on a vmware16 virtual machine

1. Set up a shared folder on the virtual machine:...

Summary of 4 methods of div+css layout to achieve 2-end alignment of css

The div+css layout to achieve 2-end alignment is ...

Nginx installation detailed tutorial

1. Brief Introduction of Nginx Nginx is a free, o...

Detailed explanation of MySQL user rights verification and management methods

This article uses examples to illustrate how to v...

How to make if judgment in js as smooth as silk

Table of contents Preface Code Implementation Ide...

Detailed explanation of formatting numbers in MySQL

Recently, due to work needs, I need to format num...

MySQL 8.0 upgrade experience

Table of contents Preface 1. First completely uni...