search
HomeWeb Front-endHTML TutorialSummary of new features of CSS3 (media query)_html/css_WEB-ITnose

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)" />

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的电脑屏幕*/}

not:

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

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

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) {}

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的设备*/}

All:

all is the default value, matching all devices;

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

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的设备*/}

min-width(min -height):

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

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

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

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

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

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的非打印机设备*/         }}

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
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
The Future of HTML: Evolution and TrendsThe Future of HTML: Evolution and TrendsMay 13, 2025 am 12:01 AM

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

Why are HTML attributes important for web development?Why are HTML attributes important for web development?May 12, 2025 am 12:01 AM

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

What is the purpose of the alt attribute? Why is it important?What is the purpose of the alt attribute? Why is it important?May 11, 2025 am 12:01 AM

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML in Action: Examples of Website StructureHTML in Action: Examples of Website StructureMay 05, 2025 am 12:03 AM

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

See all articles

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 Article

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.