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:
media_type |
device type description | /tr>
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> CSS3 Media Queries
for responsive web design