This article will share with you an introduction to media queries in CSS3. It has certain reference value and I hope it will be helpful to everyone's learning.
Responsive web design is becoming more and more popular nowadays, but responsive design also brings some problems of its own, such as slow loading. But now there is a way to solve this problem very well. We can use the media query method to solve the problem of adapting the style to different devices. Next, we will introduce it in detail in the article.
【Recommended course: CSS3 Tutorial】
Media Query
Media queries in CSS3 can call different styles according to the size of the user's device. It is a simple and efficient way to serve different content to different devices. The most commonly used queries are those that handle viewport height and width.
Media queries can be used for the following:
(1) Conditionally apply styles using CSS @media and at-rules.
(2) ,
(3) In order to test and monitor the media status, use the Window.matchMedia() and JavaScript methods.
Media Type
all: Works on all devices.
print: For paginated materials and documents viewed on screen in print preview mode.
screen: Mainly suitable for screens.
speech: Mainly suitable for speech synthesizers.
Media function
Due to space issues, we only show you some of the media query functions.
| Name | Description |
| width | Visual width |
| height | Visual height |
| aspect-ratio | Viewport aspect ratio aspect ratio |
| orientation | The direction of the viewport |
| resolution | The pixel density of the output device |
| prefers-reduced-transparency | Transparency settings |
| grid | Whether the device uses a grid or bitmap screen |
| update | How often the output device modifies the appearance of the content |
| overflow-block | How the output device handles the edge The content of the block axis overflowing the viewport |
| overflow-inline | can scroll the content of the viewport overflowing along the inline axis |
Example:
You can use the and keyword to combine media functions with media types or with other media functions, such as limiting the style to landscape devices with a width of at least 30em long
@media (min-width: 30em) and (orientation: landscape) { ... }
Example:
<style>
@media (max-width: 960px){
body{
background: pink;
}
}
</style>
The above example indicates that when the page is smaller than 960px, the page will turn pink
max- width: represents the maximum width. When it is less than this width, the following function will be called
Rendering

Summary: The above is the entire content of this article , I hope this article can give everyone a certain understanding of media inquiries.
The above is the detailed content of What are media queries in CSS3. For more information, please follow other related articles on the PHP Chinese website!
How much specificity do @rules have, like @keyframes and @media?Apr 18, 2025 am 11:34 AMI got this question the other day. My first thought is: weird question! Specificity is about selectors, and at-rules are not selectors, so... irrelevant?
Can you nest @media and @support queries?Apr 18, 2025 am 11:32 AMYes, you can, and it doesn't really matter in what order. A CSS preprocessor is not required. It works in regular CSS.
Quick Gulp Cache BustingApr 18, 2025 am 11:23 AMYou should for sure be setting far-out cache headers on your assets like CSS and JavaScript (and images and fonts and whatever else). That tells the browser
In Search of a Stack That Monitors the Quality and Complexity of CSSApr 18, 2025 am 11:22 AMMany developers write about how to maintain a CSS codebase, yet not a lot of them write about how they measure the quality of that codebase. Sure, we have
Datalist is for suggesting values without enforcing valuesApr 18, 2025 am 11:08 AMHave you ever had a form that needed to accept a short, arbitrary bit of text? Like a name or whatever. That's exactly what is for. There are lots of
Front Conference in ZürichApr 18, 2025 am 11:03 AMI'm so excited to be heading to Zürich, Switzerland for Front Conference (Love that name and URL!). I've never been to Switzerland before, so I'm excited
Building a Full-Stack Serverless Application with Cloudflare WorkersApr 18, 2025 am 10:58 AMOne of my favorite developments in software development has been the advent of serverless. As a developer who has a tendency to get bogged down in the details
Creating Dynamic Routes in a Nuxt ApplicationApr 18, 2025 am 10:53 AMIn this post, we’ll be using an ecommerce store demo I built and deployed to Netlify to show how we can make dynamic routes for incoming data. It’s a fairly


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment






