A summary of the usage of some @ rules in 1:css 2: An explanation of @media usage

Source: Internet
Author: User

Start researching responsive web design, CSS3 Media queries is getting started.

Media Queries, which allows you to apply different style sheets by allowing you to add expressions to determine the environment of your media. In other words, it allows us to change the layout of the page without changing the content to precisely adapt to different devices.

So, how does Media queries work?

Two ways, one is to determine the size of the device directly in link, and then reference a different CSS file:

<link rel= "stylesheet" type= "Text/css" href= "stylea.css" media= "screen and (min-width:400px)" >

This means that when the width of the screen is greater than or equal to 400px, the application stylea.css

In the media properties:

    • Screen is one of the media types, CSS2.1 defines 10 media types
    • and is called a keyword, other keywords also include not (excluding a device), only (qualifying a device)
    • (min-width:400px) is the media feature, which is placed in a pair of parentheses. See the relevant Media features section for complete features
<link rel= "stylesheet" type= "Text/css" href= "styleb.css" media= "screen and  (min-width:600px) and (max-width: 800px) ">

This means that when the width of the screen is greater than 600 and less than 800, the application styleb.css

Other properties can be seen here: http://www.swordair.com/blog/2010/08/431/

Another way, which is written directly in the <style> tag:

@media screen and (max-width:600px) {/* Apply the following CSS style */  . class {    background: #ccc;  }} When the display size is less than 600px.

The notation is preceded by @media, and the other is the same as the media property in link

Actually basically is the style covers ~, judging the device, and then referencing different style file overrides.

Note that because the page adjusts the layout based on the width of the screen, you cannot use an absolute width layout or an element with an absolute width. This is very important, otherwise a horizontal scroll bar will appear.

Add: Keywords in media query that aren't only

Today in a group of friends asked @media only screen and (min-width:320px) what is only meant to check some information.

Not:not is used to exclude certain devices, such as @media not print (non-printing devices),

Only: Used to set a particular type of media. For mobile devices that support media queries, if the only keyword exists, the mobile device's Web browser ignores the only keyword and applies the style file directly to the following expression. For devices that do not support media queries but are able to read a Web browser of type media type, the style file is ignored when the only keyword is encountered.

All: All devices, this should often be seen

There are other things:

/tr>

media_type

device type description

all

All devices

aural

auditory device

braille

dot haptic device

handled

portable devices such as mobile phones, tablets

print

print preview etc

projection

projection device

screen

monitors, notebooks, mobile devices

tty

devices such as typewriters or terminals

tv

TV and other device types

embossed

Braille printer

Related Information extension: http://book.51cto.com/art/201204/328362.htm

Http://www.w3cplus.com/content/css3-media-queries

Http://www.w3.org/TR/CSS2/media.html#media-types

----------------------------------Gorgeous split-line-----------------------------------------------------------

Here is the demo

A three-column layout, in different sizes, into two columns, and then into a column ~

Code:

<! DOCTYPE html>

Reference article: http://www.swordair.com/blog/2010/08/431/

http://www.zhangxinxu.com/wordpress/2011/08/css3-media-queries%E7%9A%84%E4%BA%9B%E9%87%8E%E5%8F%B2%E5%A4%96%E4%BC%A0/

Http://webdesignerwall.com/tutorials/css3-media-queries

Http://www.ruanyifeng.com/blog/2012/05/responsive_web_design.html

A summary of the usage of some @ rules in 1:css 2: An explanation of @media usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.