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:
<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
<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><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Viewport"content= "Width=device-width, initial-scale=1" /><title>Css3-media-queries-demo</title><style>Body, Div, DL, DT, DD, UL, OL, Li, H1, H2, H3, H4, H5, H6, Pre, form, fieldset, input, textarea, p, blockquote, TH, TD { padding:0; margin:0;}. content{zoom:1;}. content:after{content: "."; Display:block; height:0; Clear:both; Visibility:hidden; }.leftbox,. rightbox{float:left; width:20%; height:500px; margin:5px; Background: #ffccf7; Display:inline; -webkit-transition:width 1s ease; -moz-transition:width 1s ease; -o-transition:width 1s ease; -ms-transition:width 2s ease; transition:width 1s ease;}. middlebox{Float:left; width:50%; height:800px; margin:5px; Background: #b1fffc; Display:inline; -webkit-transition:width 1s ease; -moz-transition:width 1s ease; -o-transition:width 1s ease; -ms-transition:width 1s ease; transition:width 1s ease;}. rightbox{background: #fffab1;} @media only screen and (min-width:1024px) {. content{width:1000px; MarGin:auto}} @media only screens and (min-width:400px) and (max-width:1024px) {. rightbox{width:0; }. leftbox{width:30%}. middlebox{width:65%}} @media only screens and (max-width:400px) {. Leftbox,. Rightbox,. middlebox{width:98%; height:200px; }}</style></Head><Body><Divclass= "Content"> <Divclass= "Leftbox"></Div> <Divclass= "Middlebox"></Div> <Divclass= "Rightbox"></Div></Div></Body></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
Original source: http://www.cnblogs.com/mofish/archive/2012/05/23/2515218.html
The CSS3 Media Queries for Responsive web design