Table of Contents
Operators:
and:
not:
, (comma):
Media Type (only a few commonly used ones will be mentioned, and links will be given for the rest):
All:
Screen:
Print:
Media Query (also some commonly used ones): //Need to pay attention The thing is, Media Query must add brackets. A bracket is a query
max-width(max-height):
min-width(min -height):
max-device-width(max-device-height):
min-device -width(min-device-height):
Home Web Front-end HTML Tutorial Summary of new features of CSS3 (media query)_html/css_WEB-ITnose

Summary of new features of CSS3 (media query)_html/css_WEB-ITnose

Jun 24, 2016 am 11:40 AM

CSS3 media queries are an expansion and improvement of CSS2 media types;

CSS2 media types only define some device keywords, while CSS3 media queries further expand such as Width, height, color and other attributes with value ranges;

The difference between media query and media type is: media query is a value or a range of values, while media type is just a match of the device (so media type is a word, and media query needs to be followed by a value, the two can be mixed);

media can be used for the link tag attribute [media]

  <link rel="stylesheet" type="text/css" href="../css/print.css" media="print and (max-width : 600px)" />
Copy after login

and css files, the following code uses media in css;

Introducing the available operators & commonly used media types and media query:

Operators:

and:

The and operator is used to match if the rules on both sides of the symbol meet the conditions

@media screen and (max-width : 600px) {/*匹配宽度小于600px的电脑屏幕*/}
Copy after login

not:

The not operator is used to negate, all those that do not satisfy this rule are matched

@media not print {/*匹配除了打印机以外的所有设备*/}
Copy after login

Please note when using not, if you do not add parentheses, some strange phenomena may occur. , Example:

@media not all and (max-width : 500px) {}/*等价于*/@media not (all and (max-width : 500px)) {}/*而不是*/@media (not all) and (max-width : 500px) {}
Copy after login

So, if you want to use not, it is more clear to add brackets explicitly

, (comma):

Equivalent to or is used to match if one of the two sides is satisfied

@media screen , (min-width : 800px) {/*匹配电脑屏幕或者宽度大于800px的设备*/}
Copy after login

All:

all is the default value, matching all devices;

@media all {/*可以过滤不支持media的浏览器*/}
Copy after login

Screen:

matches computer screens;

Print:

Match the printer (it will also match when printing preview) [My resume has a set of styles specifically for printing~]

Commonly used Generally speaking, these three types are the only ones. If you are interested in the other Media Type, you can read the description of W3School or the documentation of W3

Media Query (also some commonly used ones): //Need to pay attention The thing is, Media Query must add brackets. A bracket is a query

max-width(max-height):

@media (max-width : 600px) {/*匹配界面宽度小于600px的设备*/}
Copy after login

min-width(min -height):

@media (min-width : 400px) {/*匹配界面宽度大于400px的设备*/}
Copy after login

max-device-width(max-device-height):

@media (max-device-width : 800px) {/*匹配设备(不是界面)宽度小于800px的设备*/}
Copy after login

min-device -width(min-device-height):

@media (min-device-width : 600px) {/*匹配设备(不是界面)宽度大于600px的设备*/}
Copy after login

It is better to use device-width/device-height when doing mobile development, because some mobile browsers will do this by default Make some scaling to the page, so matching according to the device width and height will be closer to the effect expected during development;

The link to W3's document that gives all Media Query attribute values ​​​​can also take a look at MDN, A volunteer has Chineseized the MDN Media Query document

media can be nested:

@media not print {    /*通用样式*/    @media (max-width:600px) {        /*此条匹配宽度小于600px的非打印机设备*/         }    @media (min-width:600px) {        /*此条匹配宽度大于600px的非打印机设备*/         }}
Copy after login

This saves the redundancy of writing not print twice. .Writing like this also has certain benefits, because some browsers may only support Media Type but not Media Query- - (Don’t ask me why I know, I’ve been through the trap)

Media Query (only the ones above) The unit of the value of ) can be px em rem (%/vh/vw/vmin/vmax etc. I haven’t tried it...it seems useless...);

Media Query is a responsive page The core of responsive pages is actually to display different effects at different resolutions;

When writing responsive page CSS, it is divided into small to large and large to small (size);

Myself It is weakly recommended to use the max-series for Media Query written from small sizes, and vice versa for large sizes;

Please point out any errors and shortcomings in this article;

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

How to implement adaptive layout of Y-axis position in web annotation? How to implement adaptive layout of Y-axis position in web annotation? Apr 04, 2025 pm 11:30 PM

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? Apr 05, 2025 am 06:15 AM

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

See all articles