css媒体查询/jquery mobile根据不同设备设定不同布局
今天在学习jquery mobile的时候,发现css中有媒体查询这个概念,用他能够进行针对媒体设备设定不同的布局状态;在单一文件下,css定义方式如下:
@media (min-width: 1001px) {#sidebar ul li a:after { content: " (" attr(data-email) ")"; font-size: 11px; font-style: italic; color: #666;}}@media (max-width: 1000px) and (min-width: 700px) {#sidebar ul li a:before { content: "Email: "; font-style: italic; color: #666;}}@media (max-width: 699px) and (min-width: 520px), (min-width: 1151px) {#sidebar ul li a { padding-left: 21px; background: url(../images/email.png) left center no-repeat;}}
@media属性值在不同的宽度值时采取不同的样式。
如果在想在不同的设备下引入不同的css,可以做如下定义:
<link rel="stylesheet" href="smartphone.css" media="only screen and (min-device-width : 320px) and (max-device-width : 480px)"><link rel="stylesheet" href="smartphone-landscape.css" media="only screen and (min-width : 321px)"><link rel="stylesheet" href="smartphone-portrait.css" media="only screen and (max-width : 320px)"><link rel="stylesheet" href="ipad.css" media="only screen and (min-device-width : 768px) and (max-device-width : 1024px)"><link rel="stylesheet" href="ipad-landscape.css" media="only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape)"><link rel="stylesheet" href="ipad-portrait.css" media="only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait)"><link rel="stylesheet" href="widescreen.css" media="only screen and (min-width : 1824px)"><link rel="stylesheet" href="iphone4.css" media="only screen and (-webkit-min-device-pixel-ratio : 1.5), only screen and (min-device-pixel-ratio : 1.5)">实例可以参考:http://css-tricks.com/examples/MediaQueriesSidebar/
http://stuffandnonsense.co.uk/blog/about/hardboiled_css3_media_queries
页:
[1]