GitHub 中文社区
回车: Github搜索    Shift+回车: Google搜索
论坛
排行榜
趋势
登录

©2025 GitHub中文社区论坛GitHub官网网站地图GitHub官方翻译

  • X iconGitHub on X
  • Facebook iconGitHub on Facebook
  • Linkedin iconGitHub on LinkedIn
  • YouTube iconGitHub on YouTube
  • Twitch iconGitHub on Twitch
  • TikTok iconGitHub on TikTok
  • GitHub markGitHub’s organization on GitHub
集合主题趋势排行榜
#

Media Queries

Media Queries are a way to target browsers by certain characteristics, features, and user preferences, then apply styles, or run other code based on those things. They are a key part of responsive web design, as they allow you to create different layouts depending on the size of the viewport, but they can also be used to detect other things about the environment your site is running on, for example whether the user is using a touchscreen rather than a mouse. Media queries are used for the following:

  • conditionally apply styles with the CSS @media and @import at-rules
  • target specific media for the <style>, <link>, <source>, and other HTML elements with the media= attribute
  • test and monitor media states using the Window.matchMedia() and EventTarget.addEventListener() methods

A media query is composed of an optional media type and any number of media feature expressions, which may optionally be combined in various ways using logical operators.

  • Media types define the broad category of device for which the media query applies. The type is optional except when using the not or only logical operators.
    • all: Suitable for all devices.
    • print: Intended for paged material and documents viewed on a screen in print preview mode.
    • screen: Intended primarily for screens.
  • Media features describe a specific characteristic of the user agent, output device, or environment. Media Queries Level 4 groups 18 media features into 5 categories.
    • Viewport/Page Characteristics
    • Display Quality
    • Color
    • Interaction
    • Video-prefixed: The spec references user agents, including TVs, that render video and graphics in two separate planes that each have their own characteristics. (upcoming Media Queries Level 5)
  • Logical operators can be used to compose a complex media query: not, and, and only. You can also combine multiple media queries into a single rule by separating them with commas.

Created by Håkon Wium Lie, W3C

发布于 June 19, 2012

Website
drafts.csswg.org
Wikipedia
维基百科
https://static.github-zh.com/github_avatars/marcj?size=40
marcj / css-element-queries

CSS Element-Queries aka Container Queries. High-speed element dimension/media queries in valid css.

CSSresponsive
JavaScript 4.26 k
2 年前
https://static.github-zh.com/github_avatars/evrone?size=40
evrone / postcss-px-to-viewport

A plugin for PostCSS that generates viewport units (vw, vh, vmin, vmax) from pixel units. The best choice to create a scalable interface on different displays by one design size.

PostCSSpixel-unitsviewport-unitsvwvhcss-scalemobile-designMedia Queriesrem-unitstaro
JavaScript 3.14 k
1 年前
https://static.github-zh.com/github_avatars/artsy?size=40
artsy / fresnel
内容违规,已屏蔽
TypeScript 1.27 k
2 个月前
https://static.github-zh.com/github_avatars/GoogleChromeLabs?size=40
GoogleChromeLabs / dark-mode-toggle

A custom element that allows you to easily put a Dark Mode 🌒 toggle or switch on your site:

Dark Modedark-theme-toggleWeb Componentscustom-elementsMedia Queries
JavaScript 1.2 k
1 个月前
https://static.github-zh.com/github_avatars/renatorib?size=40
renatorib / react-sizes

↔️ Hoc to easily map window sizes to props.

Reacthochigh-order-componentMedia Queriesresponsive
JavaScript 717
3 年前
https://static.github-zh.com/github_avatars/mg901?size=40
mg901 / styled-breakpoints

Simple and powerful breakpoints for styled components and emotion.

styled-componentsbreakpointMedia Queriescss-in-jscss-in-reactmediaReactemotionTypeScriptPreact.jsresponsive-designresponsive-layout
JavaScript 555
5 天前
https://static.github-zh.com/github_avatars/stowball?size=40
stowball / eqio

A simple, tiny alternative to element/container queries

JavaScriptCSSresponsive-designelement-queriescontainer-queriesMedia Queries
JavaScript 426
2 年前
https://static.github-zh.com/github_avatars/flexdinesh?size=40
flexdinesh / react-socks

🎉 React library to render components only on specific viewports 🔥

Media QueriesviewportReactLibrary
JavaScript 426
1 年前
https://static.github-zh.com/github_avatars/wswmsword?size=40
wswmsword / postcss-mobile-forever

PostCSS 伸缩视图转换插件。PostCSS plugin for viewport scaling. Optimized postcss-px-to-viewport/postcss-pxtorem for mobile.

PostCSScss-scaleMedia Queriesmobile-designpixel-unitsviewport-unitsresponsive-web-designCSSmobile-first
Vue 416
3 个月前
https://static.github-zh.com/github_avatars/Valexr?size=40
Valexr / Slidy

📸 Sliding action script

SvelteJavaScriptTypeScriptcarouselsliderslideshowReactMedia QueriessolidjsVue.jsWeb Componentsanimations
TypeScript 351
8 天前
https://static.github-zh.com/github_avatars/lolmaus?size=40
lolmaus / breakpoint-slicer

Slice media queries with ease

Media Queriesbreakpointresponsive-web-designresponsive-designSass
SCSS 345
2 年前
https://static.github-zh.com/github_avatars/kristerkari?size=40
kristerkari / react-native-css-modules

Style React Native components using CSS, PostCSS, Sass, Less or Stylus.

React NativeCSS ModulesCSSSassPostCSSLessStylus (Disambiguation)Media Queriesviewport-unitscss-variables
335
1 年前
https://static.github-zh.com/github_avatars/JNavith?size=40
JNavith / tailwindcss-theme-variants

Media-query- or JavaScript-based theme variants with fallback for Tailwind CSS

Tailwind CSStailwindcss-pluginthemingMedia Queriescss-selectorsDark Mode
TypeScript 198
2 年前
https://static.github-zh.com/github_avatars/seungyeub?size=40
seungyeub / awesome-web-styling

Awesome Web Styling with CSS Animation Effects ⭐️

HTMLCSS动画Webdesignmarkupstylingspinnerloadingcheckboxtextnavuilistpagebuttonslide
CSS 163
3 年前
https://static.github-zh.com/github_avatars/yunusga?size=40
yunusga / postcss-sort-media-queries

PostCSS plugin for sorting and combining CSS media queries with mobile-first / desktop-first methodologies.

PostCSSCSSMedia Queriesmediaquerymobile-firstsortmq
JavaScript 149
5 个月前
https://static.github-zh.com/github_avatars/mvrlin?size=40
mvrlin / nuxt-viewport

🌈 Define custom viewports for your Nuxt project

nuxt-moduleviewportMedia QueriesNuxt.js
TypeScript 148
1 个月前
https://static.github-zh.com/github_avatars/ZeeCoder?size=40
ZeeCoder / container-query

A PostCSS plugin and Javascript runtime combination, which allows you to write container queries in your CSS the same way you would write media queries.

rwdresponsive-designresponsivePostCSSCSSbrowserQuery (disambiguation)JavaScriptcomponentmodule
JavaScript 139
3 年前
https://static.github-zh.com/github_avatars/Dan503?size=40
Dan503 / mq-scss

Extremely powerful Sass media query mixin. Allows you to create almost any media query you can imagine.

mixinsMedia QueriesresponsiveSassmediaQuery (disambiguation)mixinbreakpoint
CSS 126
6 年前
https://static.github-zh.com/github_avatars/pauloapi?size=40
pauloapi / media-queries-scss-mixins

Media Queries SCSS Mixins

Media Queriesflex-layoutSass
SCSS 87
3 年前
https://static.github-zh.com/github_avatars/dvpnt?size=40
dvpnt / styled-media-helper

💅 Helps manage media queries with styled components

styled-componentsMedia QueriesCSSbreakpointcss-in-jscssinjscss-in-reactmedia
JavaScript 76
2 年前
loading...