注意, css 的诞生最早是为了适应富文本的流式布局, 至今遗留了很多流式风格的布局性质.使用时详查文档,不可类比桌面UI布局而想当然
坑: border-radius 设置为纯数字时,不被 chrome 接受,而 vscode, scss 等开发工具链也没有对此进行报错提示。
_name.scss
文件意味着只用来 import, SCSS不对它编译成CSS; import时可省略下划线。margin:0 auto
width:600px; height:50px; position:fixed; margin:auto; top:0; left:0; right:0;
position:fixed; top:50%; left: 50%; width:600px; height:50px; margin-left: -300px; margin-top: -25px;
height
与 line-height
相同overflow:hidden
; max-height
与overflow:auto
配合可在元素内容过高时才出现滚动条margin-top
影响了父级元素的margin-top
, 可以在父级元素使用overflow:hidden
来避免.word-break: break-all
$form.find(':input:not(:disabled)').prop('disabled',true);//disable all $form.find(':input:disabled').prop('disabled', false);//enable all
-webkit-transform
cursor
可直接指定鼠标在范围内的样式width: 80%; margin-left: auto; marin-right: auto;
详见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 */
W3C positioning-scheme CSS 2.1 defines three positioning schemes:
Inline
items are laid out in the same way as the letters in words in text, one after the other across the available space until there is no more room, then starting a new line below. Block
items stack vertically, like paragraphs and like the items in a bulleted list. Normal flow also includes relative positioning of block or inline items, and run-in boxes.
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.
normal flow
normal flow
, and then shifted or offset from that position. Subsequent flow items are laid out as if the item had not been moved.absolute positioning
. The element is positioned in relation to its nearest non-static ancestor.absolutely positioned
in a fixed position on the screen even as the rest of the document is scrolled.
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.
floats
to the left of the line that it would have appeared in; other items may flow around its right side.floats
to the right of the line that it would have appeared in; other items may flow around its left side.clear:left
), right (clear:right
) or both sides (clear:both
).CSS选择器优先级:详见MDN
元素布局上分位块级元素(block)与行内元素(inline), 行内元素排列行为类似文本,先横排,没空间才换行。 块级元素直接换行(垂直排列),比如div
p
等。而像span
a
等则为行内元素。 这两者在定位、大小设置上行为有差异, 可以使用display
来改变元素类型。
在布局上,行内框在一行中水平布置。可以使用水平内边距、边框和外边距调整它们的间距。但是,垂直内边距、边框和外边距不影响行内框的高度。由一行形成的水平框称为行框(Line Box),行框的高度总是足以容纳它包含的所有行内框。不过,设置行高可以增加这个行框的高度——但还是决定不了行内框的高度!
浏览器含有默认的CSS设置,比如ul标签含有默认的上下margin, 去除各个浏览器的默认设置,可以使用 http://cssreset.com, 把提供的css代码拷贝来就行,但是一些默认样式可能就需要自己来设置了。