Media queries are mostly used in responsive web pages.
1. Initialization settings:
In the HTML file, insert a sentence in the
tag at the top of the webpage:<meta>
This sentence is to make an initialization setting for the responsive webpage, which mainly includes:
name="viewport": mark the display device as the viewport;
width = device-width: the width is equal to the width of the current device;
initial-scale: the initial scaling ratio (default setting is 1.0);
minimum -scale: The minimum ratio that the user is allowed to zoom to (the default setting is 1.0);
maximum-scale: The maximum ratio the user is allowed to zoom to (the default setting is 1.0);
user-scalable: Whether the user can manually zoom (the default setting is 1.0) no, because we don't want users to zoom in or out of the page).
2. Solve the compatibility problem of IE browser:
Because IE browser (IE8) does not support media in HTML5 and CSS3, the JS file used to solve the compatibility problem of IE browser must be loaded:
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
The file link address pointed to by the src attribute in the two <script></script> tags is the file at the fixed address. It can be referenced directly from another location without downloading to local reference.
3. Set the rendering mode of IE to the highest:
Nowadays, many people’s IE browsers have been upgraded to IE9 or above. At this time, many strange things will happen. For example, it is IE9 browser now, but the browser’s The document mode is IE8. In order to prevent this situation, we need the following code to make IE’s document mode always up to date:
<meta>
Of course there is a more powerful way of writing:
<meta>
A chrome=1 is added after this code. This is due to Google Chrome Frame (Google Embedded Browser Framework GCF). If the user's computer installs this chrome plug-in, the IE browser in the computer can avoid version factors and use Webkit engine and V8 engine for typesetting and calculation. Of course, if the user does not install this plug-in, this code will cause the IE browser to display the effect in the highest document mode.
4. CSS3 media media query is written as:
@media screen and (max-width: 960px){ body{ background: #000; } }
This is a standard way of writing media. In the CSS file, it means: when the page is smaller than 960px, execute the following CSS code. The specific content is ignored for the time being.
For screen in the above code, it means to tell the device to use serif fonts when printing the page, and to use sans-serif fonts when displaying on the screen. At present, many websites directly omit screen, so there is no need to consider the user's need to print web pages, so there is another way of writing:
@media (max-width: 960px){ body{ background: #000; } }
In line with the principle of rigorous thinking, I personally will not use this way of writing.
5. CSS3 media query body code combination:
In responsive web page layout, media query code combination needs to be continuously used. The main function is to determine the width of the adapted screen and apply different CSS according to various width conditions. style.
For example, when the screen width is equal to 960px, change the background color of the web page to red:
@media screen and (max-device-width:960px){ body{ background:red; } }
For example, when the screen width is maximum 960px (less than 960px), change the background color of the web page to black:
@media screen and (max-width: 960px){ body{ background: #000; } }
Like when When the screen width is at least 960px (greater than 960px), change the background color of the web page to orange:
@media screen and (min-width:960px){ body{ background:orange; } }
More common is a mixed use, such as when the screen width is between 960px and 1200px, change the background color of the web page to orange Is yellow:
@media screen and (min-width:960px) and (max-width:1200px){ body{ background:yellow; } }
6. Overall development idea:
The general idea of using media queries in CSS3 is to determine the width range of the web page in different devices. There may be three such ranges (PC, tablet, mobile phone), and There may be four types (PC, tablet, medium and large screen mobile phone, small screen mobile phone), of course, there may be only two types (tablet, mobile phone, PC side does not need to be used as the object of CSS3 media query when developing a separate version), and for Apply different CSS styles to the required page elements in various width ranges to adapt to various devices.
7. Width issues in responsive web development:
In actual development, it is usually necessary to set the maximum width of responsive web pages. Once the maximum width is ignored, bloated or fragmented web page layout will cause visual flooding, which is what we Often said it looks very low.
Also let’s talk about the width of web pages in current display devices (due to space issues, I won’t start with the Industrial Revolution). The most common widths at present are basically: PC side greater than or equal to 960px (1920px, 1600px, 1440px , 1280px, 1140px, 960px), tablets between 960px and 640px (768px, 640px), and mobile phones below 640px (480px, 320px). The above widths have existed for a long time, and the width of web pages in display devices will remain like this for a long time. In this state, when it comes to responsive web page width design, it is basically enough to consider these dimensions.
8. Summary of all parameters of media media query:
The media query also includes related functions that are not commonly used, as follows:
width: browser visible width,
height: browser Visual height,
device-width: the width of the device screen,
device-height: the height of the device screen,
orientation: detect whether the device is currently in landscape or portrait mode,
aspect-ratio:检测浏览器可视宽度和高度的比例(例如:aspect-ratio:16/9),
device-aspect-ratio:检测设备的宽度和高度的比例,
color:检测颜色的位数(例如:min-color:32就会检测设备是否拥有32位颜色),
color-index:检查设备颜色索引表中的颜色(他的值不能是负数),
monochrome:检测单色楨缓冲区域中的每个像素的位数(这个太高级,估计咱很少会用的到),
resolution:检测屏幕或打印机的分辨率(例如:min-resolution:300dpi或min-resolution:118dpcm),
grid:检测输出的设备是网格的还是位图设备。
9.扩展——在CSS2中同样有媒体查询:
media媒体查询并不是CSS3诞生之后的专用功能,早在CSS2开始就已经支持media,比如:
在HTML文件中的
标签中写入这句:<link>
以上是CSS2实现的衬线用法,href属性中写入在某单一显示设备中链接的CSS文件,但仅供入门,
如要判断移动设备是否为纵向放置的显示屏,可以这样写:
<link>
如要让小于960px的页面执行指定的CSS样式文件,可以这样写:
<link>
当然,CSS2中的媒体查询方法放到现在并不推荐使用,最大的弊端在于这样会增加页面http的请求次数,增加页面负担,使用CSS3中的媒体查询才是目前的最佳方法。
更多CSS3中的media媒体查询相关文章请关注PHP中文网!

有用户在启动联想笔记本时,出现checkingmedia无法启动的问题,让人不知所措,那么联想电脑checkingmedia开不了机如何解决?本期教程就为大家带来联想笔记本出现checkingmedia无法启动原因及解决办法。导致原因:1、硬盘损坏:若联想笔记本存在硬盘损坏、故障的问题,会导致笔记本显示checkingmedia且开不了机。操作系统损坏:若联想笔记本的操作系统损坏,会导致笔记本显示checkingmedia且开不了机。2、重新开机,按F12进入BIOS,在“启动”项

两种方法:1、利用display属性,只需给元素添加“display:none;”样式即可。2、利用position和top属性设置元素绝对定位来隐藏元素,只需给元素添加“position:absolute;top:-9999px;”样式。

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

自适应布局又称“响应式布局”,是指可以自动识别屏幕宽度、并做出相应调整的网页布局;这样的网页能够兼容多个不同的终端,而不是为每个终端做一个特定的版本。自适应布局是为解决移动端浏览网页而诞生的,能够为使用不同终端的用户提供很好的用户体验。

实现方法:1、使用“:active”选择器选中鼠标点击图片的状态;2、使用transform属性和scale()函数实现图片放大效果,语法“img:active {transform: scale(x轴放大倍数,y轴放大倍数);}”。

css3中的动画效果有变形;可以利用“animation:动画属性 @keyframes ..{..{transform:变形属性}}”实现变形动画效果,animation属性用于设置动画样式,transform属性用于设置变形样式。

在css3中,可以利用“animation-timing-function”属性设置动画旋转速度,该属性用于指定动画将如何完成一个周期,设置动画的速度曲线,语法为“元素{animation-timing-function:速度属性值;}”。

css3线性渐变可以实现三角形;只需创建一个45度的线性渐变,设置渐变色为两种固定颜色,一个是三角形的颜色,另一个为透明色即可,语法“linear-gradient(45deg,颜色值,颜色值 50%,透明色 50%,透明色 100%)”。


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 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
