Movatterモバイル変換


[0]ホーム

URL:


  1. Веб-технологии для разработчиков
  2. CSS: каскадные таблицы стилей
  3. Руководство по CSS
  4. At-rules
  5. @media

This page was translated from English by the community.Learn more and join the MDN Web Docs community.

View in EnglishAlways switch to English

@media

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since июль 2015 г..

* Some parts of this feature may have varying levels of support.

Описание

CSS@-правило@media может быть использовано для применения части стилей при соблюдении условия одного или несколькихмедиавыражений.

Примечание:В JavaScript правила, созданные с помощью@media могут быть получены через интерфейс объектной модели CSSCSSMediaRule.

Синтаксис

@-правило@media можно разместить на верхнем уровне CSS или внутри любого фрагментаусловной группы @-правил.

css
/* На верхнем уровне кода */@media screen and (min-width: 900px) {  article {    padding: 1rem 3rem;  }}/* Вложено в другое условное @-правило */@supports (display: flex) {  @media screen and (min-width: 900px) {    article {      display: flex;    }  }}

Для рассмотрения синтаксиса медиавыражений, см.Использование медиавыражений.

Формальный синтаксис

@media =
@media<media-query-list> {<rule-list> }

A<media-query> is composed of a optional media type and/or a number of media features.

Типы

all

Подходит для всех устройств.

print

Intended for paged material and for documents viewed on screen in print preview mode. Please consult the section onpaged media, and themedia section of the Getting Started tutorial for information about formatting issues that are specific to paged media.

screen

Предназначен в первую очередь для цветных компьютерных экранов.

speech

Предназначен для синтезаторов речи.

Примечание:CSS2.1 и Media Queries 3 определили несколько дополнительных значений (tty,tv,projection,handheld,braille,embossed,aural), но они устарели вMedia Queries 4 и не рекомендуется к использованию.

Media Features

Eachmedia feature tests for one specific feature of the browser or device.

ИмяSummaryNotes
widthViewport width
heightViewport height
aspect-ratioWidth-to-height aspect ratio of the viewport
orientationOrientation of the viewport
resolutionPixel density of the output device
scanScanning process of the output device
gridIs the device a grid or bitmap?
update-frequencyHow quickly (if at all) can the output device modify the appearance of the contentAdded in Media Queries Level 4
overflow-blockHow does the output device handle content that overflows the viewport along the block axis?Added in Media Queries Level 4
overflow-inlineCan content that overflows the viewport along the inline axis be scrolled?Added in Media Queries Level 4
colorNumber of bits per color component of the output device, or zero if the device isn't color.
color-indexNumber of entries in the output device's color lookup table, or zero if the device does not use such a table.
display-modeThe display mode of the application, as specified in the web app manifest'sdisplay member.Defined in theWeb App Manifest spec.
monochromeBits per pixel in the output device's monochrome frame buffer, or 0 if the device is not monochrome.
inverted-colorsIs the user agent or underlying OS inverting colors?Added in Media Queries Level 4
pointerIs the primary input mechanism a pointing device, and if so, how accurate is it?Added in Media Queries Level 4
hoverDoes the primary input mechanism allow the user to hover over elements?Added in Media Queries Level 4
any-pointerIs any available input mechanism a pointing device, and if so, how accurate is it?Added in Media Queries Level 4
any-hoverDoes any available input mechanism allow the user to hover over elements?Added in Media Queries Level 4
light-levelCurrent ambient light levelAdded in Media Queries Level 4
scriptingIs scripting (e.g. JavaScript) available?Added in Media Queries Level 4
device-widthWidth of the rendering surface of the output deviceDeprecated in Media Queries Level 4
device-heightHeight of the rendering surface of the output deviceDeprecated in Media Queries Level 4
device-aspect-ratioWidth-to-height aspect ratio of the output deviceDeprecated in Media Queries Level 4
-webkit-device-pixel-ratioНе стандартноNumber of physical device pixels per CSS pixelNonstandard; WebKit/Blink-specific. If possible, use theresolution media feature instead.
-webkit-transform-3dНе стандартноAre CSS 3Dtransforms supported?Nonstandard; WebKit/Blink-specific
-webkit-transform-2dНе стандартноAre CSS 2Dtransforms supported?Nonstandard; WebKit-specific
-webkit-transitionНе стандартноAre CSStransitions supported?Nonstandard; WebKit-specific
-webkit-animationНе стандартноAre CSSanimations supported?Nonstandard; WebKit-specific

Примеры

css
@media print {  body {    font-size: 10pt;  }}@media screen {  body {    font-size: 13px;  }}@media screen, print {  body {    line-height: 1.2;  }}@media only screen and (min-device-width: 320px) and (max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2) {  body {    line-height: 1.4;  }}

Спецификации

Specification
Media Queries Level 4
# media-descriptor-table
CSS Conditional Rules Module Level 3
# at-media

Совместимость с браузерами

Смотрите также

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp