移动网站开发 CSS(取其精华版)

精选自原文:移动网站开发——CSS

CSS Mobile Profile 2.0中的CSS支持

因为这是CSS 2.1的一个子集,那么我们对这个规范的内容应该不会陌生,我们通过这个表格可以很直观的看到CSS MP对CSS的支持情况:

支持的 不支持的
选择器 全局选择器(*)、类型选择器(比如h1, div, p等)、子选择器(p>span)、链接伪类 (:link,:visited)、动态伪类(:active, :focus)、类选择器、id选择器、分组(h1,h2,h3{}…) :first-child、:hover 、:lang() 伪类, :first-letter 、:first-line 伪元素, 兄弟选择器(比如h1 + p),属性选择器 (比如 a[href], a[target=”_blank”])
背景和边框 background, background-color, background-image, background-repeat, background-attachment, background-position, border, border-width, border-color, border-style(注1)
定位 position, top, right, bottom, left, z-index
列表 list-style, list-style-image, list-style-type list-style-position
基本的盒模型 display(注2), margin, padding, height, min-height, max-height, width, min-width, max-width, float, clear, visibility, overflow(注3), overflow-style(注4)
色彩 color
字体 font, font-family, font-style, font-variant, font-weight, font-size(注5)
文字 text-indent, text-align, text-decoration(注6), text-transform, white-space word-spacing, letter-spacing, unicode-bidi
线形 vertical-align(注7) line-height
基本的用户界面 utline, outline-color, outline-style, outline-width cursor
滚动 marquee-style, marquee-direction, marquee-play-count, marquee-speed
@规则 @charset, @import, @media(注8), @namespace @page

  • 注1:border-style只支持常用的none、dotted、dashed、solid和inherit,其它的几个并没有被列入规范。
  • 注2:display仅限于inline、block、list-item、none和inherit,不支持run-in和inline-block
  • 注3:overflow只支持auto
  • 注4:overflow-sytle只支持marquee值
  • 注5:font-size只支持大小关键词,比如small、medium、bigger等,px、pt和百分比等不被支持。
  • 注6:text-decoration只支持none、blink、underline和inherit等,overline、line-trough不被支持。
  • 注7:vertical-align 只支持top, middle, bottom, baseline 和inherit。sub, super, text-top, text-bottom, 百分比和长度不被支持
  • 注8:@media规则只支持 handheld 和all 媒体类型。

用法与浏览器支持

[html]
<link rel="stylesheet" media="handheld" href="">
[/html]
其实考虑到传统手机的自身的限制和移动网络速度的限制,通过media type来加载外部样式是不可取的,通常用于移动版页面的样式不多,而多加载一个外部样式的代价是巨大的。所以,大部分的网站的移动版采用在head中嵌入样式表的方式。

特别值得一提的是,mobile webkit(包括iphone safari和android chrome lite等)不支持handheld

参考