目录

注意, css 的诞生最早是为了适应富文本的流式布局, 至今遗留了很多流式风格的布局性质.使用时详查文档,不可类比桌面UI布局而想当然

坑: border-radius 设置为纯数字时,不被 chrome 接受,而 vscode, scss 等开发工具链也没有对此进行报错提示。

Cascading Style Sheets

Flex

Tools

Libs

PostCSS

LESS

SCSS

Tips

Selector

css3 media queries

Calculating a selector's specificity

详见MDN

Copy from W3C CSS 3 selector.

A selector's specificity is calculated as follows:

Selectors inside the negation pseudo-class are counted like any other, but the negation itself does not count as a pseudo-class.

Concatenating the three numbers a-b-c (in a number system with a large base) gives the specificity.

Examples:

 
*               /* a=0 b=0 c=0 -> specificity =   0 */
LI              /* a=0 b=0 c=1 -> specificity =   1 */
UL LI           /* a=0 b=0 c=2 -> specificity =   2 */
UL OL+LI        /* a=0 b=0 c=3 -> specificity =   3 */
H1 + *[REL=up]  /* a=0 b=1 c=1 -> specificity =  11 */
UL OL LI.red    /* a=0 b=1 c=3 -> specificity =  13 */
LI.red.level    /* a=0 b=2 c=1 -> specificity =  21 */
#x34y           /* a=1 b=0 c=0 -> specificity = 100 */
#s12:not(FOO)   /* a=1 b=0 c=1 -> specificity = 101 */

Positioning

W3C positioning-scheme CSS 2.1 defines three positioning schemes:

Position: top, bottom, left, and right

There are four possible values of the position property. If an item is positioned in any way other than static, then the further properties top, bottom, left, and right are used to specify offsets and positions.

Float and clear

The float property may have one of three values. Absolutely positioned or fixed items cannot be floated. Other elements normally flow around floated items, unless they are prevented from doing so by their clear property.

tips

CSS选择器优先级:详见MDN

  • 浏览器用户设置 > 浏览器内置 > 网页行内style > 非行内style
  • css选择器的优先,分三组计算次数1.ID, 2.类、伪类、属性, 3.标签, 三组数量按奥运会金银铜奖牌板的方式排序,来决定优先级。

元素布局上分位块级元素(block)与行内元素(inline), 行内元素排列行为类似文本,先横排,没空间才换行。 块级元素直接换行(垂直排列),比如div p 等。而像span a 等则为行内元素。 这两者在定位、大小设置上行为有差异, 可以使用display来改变元素类型。

在布局上,行内框在一行中水平布置。可以使用水平内边距、边框和外边距调整它们的间距。但是,垂直内边距、边框和外边距不影响行内框的高度。由一行形成的水平框称为行框(Line Box),行框的高度总是足以容纳它包含的所有行内框。不过,设置行高可以增加这个行框的高度——但还是决定不了行内框的高度!

浏览器含有默认的CSS设置,比如ul标签含有默认的上下margin, 去除各个浏览器的默认设置,可以使用 http://cssreset.com, 把提供的css代码拷贝来就行,但是一些默认样式可能就需要自己来设置了。