Media type in CSS media type_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:58:04
Original
1271 people have browsed it

The role of madia type

First of all, we need to understand that the HTML pages we usually write may be displayed in different media types, such as they may be displayed on the screen or on paper print on. Then when the page is displayed in different media types, the required styles may be different. For example, generally, the font size of the page should be larger when displayed on the screen, and smaller when displayed on paper media. So how do you tell someone what media type a style is suitable for? This is achieved by declaring media type.

How to declare media type

Common media types are: all, screen, print, handled, speech, etc.;

Note that media types are case-sensitive and can only be Lowercase;

When the browser encounters an incorrect media type or a non-existent media type, it will ignore the existence of this media type, such as:

@media screen, 3D {  P { color: green; }}
Copy after login
Here, 3D is not If the media type exists, the browser will parse it as

@media screen {  P { color: green; }}
Copy after login

How to declare the media type for the style, see the following sample code:

<span style="font-size:14px;"><head>    <link rel="stylesheet" type="text/css" href="mystyle1.css" media="screen,print"><span style="color:#ff6666;"><!--mystyle1样式表只应用于screen和print媒介--></span>    <style>        @import url("mystyle2.css") screen,print;<span style="color:#ff6666;">/*mystyle2样式表只应用于screen和print媒介*/</span>        @media screen {            body{font-size:14px;}   <span style="color:#ff6666;"> /*在screen媒介中body字体为14px*/</span>        }        @media print {            body{font-size: 10px;}  <span style="color:#ff6666;"> /*在print媒介中body字体为10px*/</span>        }        body{color: #ff0000;}<span style="color:#ff6666;">/*若样式没有声明媒体类型,相当于媒体类型为all,则此样式会应用于所有的媒体类型*/</span>    </style></head></span>
Copy after login


For more information about media types, please refer to the W3C official website: http://www.w3.org/TR/CSS21/media.html


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template