0

0

What is the difference between “screen” and “only screen” in media queries?

WBOY

WBOY

发布时间:2023-08-19 14:37:06

|

1130人浏览过

|

来源于tutorialspoint

转载

what is the difference between “screen” and “only screen” in media queries?

In CSS, media queries play an important role in creating a responsive web design, and nowadays responsive design is one of the important things every website requires to attract visitors.

In general, we can write media queries using the @media CSS rule. However, we can use the different conditions and keywords in a media query to target different devices. For example, mobile devices, desktop devices, printer screens, etc.

In this tutorial, we will learn the difference between the ‘screen’ and ‘only screen’ in media queries.

什么是媒体查询中的屏幕?

In CSS, we use the ‘screen’ keyword inside the media queries to target all devices with a screen, such as tablets, mobile, desktops, printers, screen readers, etc.

Syntax

Users can follow the syntax below to use the screen keyword in media queries.

@media screen and (condition) {
   /* CSS code */
}

In the above syntax, a condition is used to set the breakpoints for the different devices.

Example 1

的中文翻译为:

示例 1

In the example below, we have used the screen keyword with the media queries in CSS. We have a div element containing the ‘text’ class name.

On the desktop, the background color of the body is ‘aqua’, but we change it to ‘yellow’ for devices with a screen size of less than 1200 px. Also, we change the style of the div element for devices of less than 1200 px.

In the output, users can change the size of the browser’s window and observe the difference in style.

Asksia
Asksia

Asksia AI - 最好的AI老师,可靠的作业助手

下载


   


   

Using the @media rule in CSS to make a responsive web design

Set the screen width less than 1200 pixels to change the style

This is a test div element.

媒体查询中唯一的屏幕是什么?

在CSS中编写媒体查询时,我们还可以使用“only”关键字与“screen”关键字一起使用。当我们使用“only”关键字时,它仅在浏览器匹配媒体类型和媒体特性时应用媒体查询中的样式。

However, older browsers have the special effect of the ‘only’ keyword. For example, suppose older browsers don’t support the media queries and media features. In that case, they shouldn’t apply the styles defined inside the media query block when the device doesn’t match the media type specifications.

However, all modern browsers ignore the ‘only’ keyword.

Syntax

Users can follow the syntax below to use the ‘only’ keyword in media queries.

@media only screen and (condition) {
   /* CSS code */
}

Example 2

In the example below, we have defined the ‘multiple’ div element, which contains five ‘single’ div elements. We have styled the ‘multiple’ and ‘single’ div elements.

Also, we have used media queries to style the webpage for devices with a width of less than 680 pixels. Users can change the size of the browser’s window and observe the difference in the design of the single and multiple div elements.



   


   

Using the @media rule in CSS to make a responsive web design

Set the screen width less than 680 pixels to change the style

Difference Between the Screen and Only Screen in Media Queries?

Here, we have explained the difference between the screen and only screen in media queries in the difference table.

的中文翻译为: 的中文翻译为:
Property属性 “screen” 媒体类型 “only screen” 媒体类型
Syntax语法 @media screen { /* CSS code */ } @media only screen { /* CSS代码 */ }
目标 它面向所有设备,如智能手机、台式机、平板电脑等。 It also targets all devices except those that don’t support the media types and features like scanners or printers.

Users learned the difference between the ‘screen’ and ‘only screen’ media types. The ‘only’ keyword has no impact in modern browsers as it always ignores the ‘only’ keyword, but it is useful for the older browsers' versions.

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
css
css

css是层叠样式表,用来表现HTML或XML等文件样式的计算机语言,不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式化。php中文网还为大家带来html的相关下载资源、相关课程以及相关文章等内容,供大家免费下载使用。

524

2023.06.15

css居中
css居中

css居中:1、通过“margin: 0 auto; text-align: center”实现水平居中;2、通过“display:flex”实现水平居中;3、通过“display:table-cell”和“margin-left”实现居中。本专题为大家提供css居中的相关的文章、下载、课程内容,供大家免费下载体验。

267

2023.07.27

css如何插入图片
css如何插入图片

cssCSS是层叠样式表(Cascading Style Sheets)的缩写。它是一种用于描述网页或应用程序外观和样式的标记语言。CSS可以控制网页的字体、颜色、布局、大小、背景、边框等方面,使得网页的外观更加美观和易于阅读。php中文网给大家带来了相关的教程以及文章,欢迎大家前来阅读学习。

760

2023.07.28

css超出显示...
css超出显示...

在CSS中,当文本内容超出容器的宽度或高度时,可以使用省略号来表示被隐藏的文本内容。本专题为大家提供css超出显示...的相关文章,相关教程,供大家免费体验。

539

2023.08.01

css字体颜色
css字体颜色

CSS中,字体颜色可以通过属性color来设置,用于控制文本的前景色,字体颜色在网页设计中起到很重要的作用,具有以下表现作用:1、提升可读性;2、强调重点信息;3、营造氛围和美感;4、用于呈现品牌标识或与品牌形象相符的风格。

761

2023.08.10

什么是css
什么是css

CSS是层叠样式表(Cascading Style Sheets)的缩写,是一种用于描述网页(或其他基于 XML 的文档)样式与布局的标记语言,CSS的作用和意义如下:1、分离样式和内容;2、页面加载速度优化;3、实现响应式设计;4、确保整个网站的风格和样式保持统一。

605

2023.08.10

css三角形怎么写
css三角形怎么写

CSS可以通过多种方式实现三角形形状,本专题为大家提供css三角形怎么写的相关教程,大家可以免费体验。

561

2023.08.21

css设置文字颜色
css设置文字颜色

CSS(层叠样式表)可以用于设置文字颜色,这样做有以下好处和优势:1、增加网页的可视化效果;2、突出显示某些重要的信息或关键字;3、增强品牌识别度;4、提高网页的可访问性;5、引起不同的情感共鸣。

397

2023.08.22

C++ 高级模板编程与元编程
C++ 高级模板编程与元编程

本专题深入讲解 C++ 中的高级模板编程与元编程技术,涵盖模板特化、SFINAE、模板递归、类型萃取、编译时常量与计算、C++17 的折叠表达式与变长模板参数等。通过多个实际示例,帮助开发者掌握 如何利用 C++ 模板机制编写高效、可扩展的通用代码,并提升代码的灵活性与性能。

7

2026.01.23

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号