跳转到帖子
在手机APP中查看

一个更好的浏览方法。了解更多

OKCCN - XenForo & IPS Plugin Marketplace

主屏幕上的全屏APP,带有推送通知、徽章等。

在iOS和iPadOS上安装此APP
  1. 在Safari中轻敲分享图标
  2. 滚动菜单并轻敲添加到主屏幕
  3. 轻敲右上角的添加按钮。
在安卓上安装此APP
  1. 轻敲浏览器右上角的三个点菜单 (⋮) 。
  2. 轻敲添加到主屏幕安装APP
  3. 轻敲安装进行确认。
  • 选择语言

CSS Media Queries

推荐的帖子

  • 行政经理

CSS Media Queries


CSS Media Queries

CSS media queries allow you to apply styles based on the characteristics of a device or the environment displaying the web page.

CSS media queries are essential for creating responsive web pages.

The CSS @media rule is used to add media queries to your style sheet.


Media Query Syntax

A media query consists of an optional media-type and one or more media-features, which resolve to either true or false.

@media [not] media-type and (media-feature: value) and (media-feature: value) {
  /* CSS rules to apply */
}

The media-type is optional. However, if you use not, you must also specify a media-type.

The result of a media query is true if the specified media-type matches the type of device, and all media-features are true. When a media query is true, the corresponding style rules are applied, following the normal cascading rules.

Meaning of the not and and keywords:

not: This optional keyword inverts the meaning of the entire media query.

and: This keyword combines a media-type and one or more media-features.


CSS Media Types

The optional media type specifies the type of media the styles are for. If media type is omitted, it will be set to "all".

Value Description
all Used for all media type devices
print Used for print preview mode
screen Used for computer screens, tablets, and smart-phones


CSS Media Features

The media feature specifies a specific characteristic of the device.

Here are some commonly used media features:

Value Description
max-height Maximum height of the viewport
min-height Minimum height of the viewport
height Height of the viewport (including scrollbar)
max-width Maximum width of the viewport
min-width Minimum width of the viewport
width Width of the viewport (including scrollbar)
orientation Orientation of the viewport (landscape or portrait)
resolution Screen resolution
prefers-color-scheme User's preferred color scheme (light or dark)

Media Queries Examples

Here, we use a media query to change the background-color of the body to lightgreen, if the width of the viewport is 480px, or wider:

Example

@media screen and (min-width: 480px) {
  body {
    background-color: lightgreen;
  }
}
Try it Yourself »

Here, we use a media query to change the background-color of the body to lightgreen, if the width of the viewport is between 480px and 768px:

Example

@media screen and (min-width: 480px) and (max-width: 768px) {
  body {
    background-color: lightgreen;
  }
}
Try it Yourself »

More Media Query Examples

For more examples on media queries, go to the next page: CSS MQ Examples.




参与讨论

你可立刻发布并稍后注册。 如果你有帐户,立刻登录发布帖子。

游客
回帖…

帐户

导航

搜索

搜索

配置浏览器推送通知

Chrome (安卓)
  1. 轻敲地址栏旁的锁形图标。
  2. 轻敲权限 → 通知。
  3. 调整你的偏好。
Chrome (台式电脑)
  1. 点击地址栏中的挂锁图标。
  2. 选择网站设置。
  3. 找到通知选项并调整你的偏好。