Table of Contents
The role of madia type
How to declare media type
Home Web Front-end HTML Tutorial Media type in CSS media type_html/css_WEB-ITnose

Media type in CSS media type_html/css_WEB-ITnose

Jun 24, 2016 am 11:58 AM
css media type media type

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


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

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What does placeholder mean in vue What does placeholder mean in vue May 07, 2024 am 09:57 AM

What does placeholder mean in vue

How to write spaces in vue How to write spaces in vue Apr 30, 2024 am 05:42 AM

How to write spaces in vue

How to get dom in vue How to get dom in vue Apr 30, 2024 am 05:36 AM

How to get dom in vue

What does span mean in js What does span mean in js May 06, 2024 am 11:42 AM

What does span mean in js

What does rem mean in js What does rem mean in js May 06, 2024 am 11:30 AM

What does rem mean in js

How to introduce images into vue How to introduce images into vue May 02, 2024 pm 10:48 PM

How to introduce images into vue

What is the function of span tag What is the function of span tag Apr 30, 2024 pm 01:54 PM

What is the function of span tag

How to wrap prompt in js How to wrap prompt in js May 01, 2024 am 06:24 AM

How to wrap prompt in js

See all articles