E[attr*=val] Element E whose attribute attr matches val anywhere within the attribute. Similar to E[attr~=val] above, except the val can be part of a word.
:scope /* Matches elements that are a reference point for selectors to match against. */
/* Selects a scoped element */ :scope { background-color: blue; } /* In CSS, :scope is the :root, since we don't have scoped CSS yet. */ /* In JS, :scope matches the element returned by querySelector(), querySelectorAll(), matches(), or el.closest() */
/* Column combinator */ col.selected || td { /* matches all cells within the column's scope*/ } :nth-column(An+B) :nth-last-column(An+B)
/* Time dimensional */ :current :future :past
/* Video & Audio */ :playing :paused
Specificity
Specificity: How it works
0-0-0: Global selector
1-0-0: ID selector
0-1-0: Class selector (Also attribute selector & pseudoclass)
0-0-1: Element Selector
Pseudo-Elements
Introduction to Pseudo-Elements
Pseudo elements
1 2 3 4 5 6 7
::first-line ::first-letter ::before ::after
/* (not in specification) */ ::selection
Pseudo-classes select elements that already exist. Pseudo-elements create “faux” elements you can style.
@media screen and (min-device-pixel-ratio: 1.5) { selector { /* properties for higher resolution screens */ property: value; } }
Syntax & Punctuation
1 2 3 4 5 6 7 8 9 10 11
/* "only" leaves out older browsers */ media="only print and (color)"
/* "and" - both parts must be true */ media="only screen and (orientation: portrait)" /* "not" - if untrue */ media="not screen and (color)" /* Comma separates selectors - any part can be true */ media="print, screen and (min-width: 480px)"
Accessibility: Color is NOT the only visual means of conveying information,indicating an action, prompting a response, or distinguishing a visual element.
appearance: Changes the appearance of buttons and other controls to resemble native controls.
Controlling Flex Items From the flex items themselves
align-self property
auto
flex-start
flex-end
center
baseline
stretch
Override the align-items on a per flex item basis
order property
1 2 3
div:nth-of-type(3n) { order: -1; }
The default value is 0. Anything lower will come before those without set values. Anything above will come after.
Flexibility & Shorthand
flex shorthand
flex-grow: How to divide the extra space. Non-negative number. default: 1.
flex-shrink: How to shrink if there’s not enough room. Non-negative number. default: 1.
flex-basis: the starting size before free space is distributed. length value, content or auto . If set to auto, sets to flex item’s main size property.
When the borders are collapsed border-spacing is relevant.
border-spacing
1
border-spacing: <length> <length>?;
The look you want is probably
1 2 3 4 5 6 7
table, td, th { border: none; }
table { border-spacing: 5px10px; }
one length: vertical and horizontal padding are the same.
two lengths: first is horizontal, second is vertical
Note: not TRouBLe
Irrelevant if border-collapse: collapse
Empty space is part of the table, not the column, tbody, row or cell.
Other Table Properties
Empty Cells
1
empty-cell: show | hide
Similar to
1 2 3
td:empty, th:empty { visibility: none; }
ignored if border-collapse: separate
applies to elements with diplay of table-cell
property of table or the cells themselves
table-layout
1
table-layout: auto | fixed
fixed renders faster
vertical-align
1
vertical-align: baseline | sub | super | text-top | text-bottom | middle | top | bottom | <percentage> | <length>
baseline Aligns the baseline of the cell with the baseline of all other cells in the row that are baseline-aligned.
top Aligns the top padding edge of the cell with the top of the row.
middle Centers the padding box of the cell within the row.
bottom Aligns the bottom padding edge of the cell with the bottom of the row.
applied to thead, tfoot, tbody, tr, td, th, but not table. negative values are ok additional values (sub, super, text-top, text-bottom, <length>, and <percentage>) equal
<table> <caption> 2017–18 Primera División: Player of the week </caption> <colgroup> <colclass="week"/> <colclass="player"/> <colclass="club"/> <colclass="stat"/> </colgroup> <thead>
Defines how the items are aligned with respect to the grid if the size of all the items combined is not the same size as the container. 定义如果组合的所有项的大小与容器的大小不相同,则项相对于网格的对齐方式。
1 2 3 4 5 6 7
justify-content: baseline | center | end | flex-end | flex-start | left | normal | right | space-around | space-between | space-evenly | start | stretch | safe | unsafe
align-content: baseline | center | end | flex-end | flex-start | left | normal | right | space-between | space-evenly | start | stretch | safe | unsafe
Tip: auto track sizes (and only auto track sizes) can be stretched by the align-content and justify-content properties 提示:自动轨道大小(只有自动轨道大小)可以通过对齐内容和对齐内容属性进行拉伸
Track Sizing & Auto Flow
When items are placed outside of the tracks defined by grid-template-rows, grid-template-columns, and grid-template-areas, implicit grid tracks by added. These properties size those tracks 当项目被放置在由网格模板行、网格模板列和网格模板区域定义的轨道之外时,添加隐式网格轨道。这些属性决定了轨迹的大小
.slide { background-image: radial-gradient(circle farthest-corner at bottom 40px right 50px, black 1%, 1%, palegoldenrod 2%, 98%, rebeccapurple 98%); }
closest-side circle: gradient ray end touches closest side. ellipse: vertical ray touches closest of top or bottom edge. horizontal ray touchest closest of right or left side.
farthest-side circle: gradient ray end touches furthest side. ellipse: vertical ray touches furthest of top or bottom edge. horizontal ray touchest furthest of right or left side.
closest-corner circle: radius is length from center of circle (position) to closest corner. ellipse: gradient ray touches corner closest to center while maintaining aspect ratio.
farthest-corner Default! circle: radius is length from center of circle (position) to furthest corner. ellipse: gradient ray touches corner furthest from center while maintaining aspect ratio.
Color Stops, Hints & Repeating
1 2 3 4 5 6 7 8 9 10 11
.slide { background-image: radial-gradient(circle closest-side at 100px, red 0%, orange 20%, yellow 40%, green 60%, blue 80%, purple 100% ); }
repeating-radial-gradient()
1 2
repeating-radial-gradient([<shape>|| <size> at <position>]? [<color-stop>[, <color-hint>]?, ]# <color-stop>)
Things to remember:
repeats the radial gradient after the 100% mark. 在100%标记后重复径向梯度。
Has no impact when ‘furthest-corner’ is used or defaults for gradient size 当使用“furthest-corner”或默认渐变大小时没有影响
Use ‘at’ with position 与position连用at
position is center of gradient 位置是梯度的中心
If shape is specified as circle or omitted, the size can be a length/percent 如果形状指定为圆形或省略,则大小可以是长度/百分比
1 2 3 4 5 6 7 8 9 10 11 12
.slide { background-image: repeating-radial-gradient(circle closest-side at 100px, red 0%, orange 20%, yellow 40%, green 60%, blue 80%, purple 100% ); }
translate(<length>[, <length>]) specifies a 2D translation by the vector [x, y], where x is the translation-value parameter for the x axis and y is the optional translation value along the y axis. parameter. If y is not provided, y==0. 通过向量[x, y]指定二维平移,其中x是x轴的平移值参数,y是沿y轴的可选平移值。参数。如果没有提供y,则y==0。
translateX(<length>) specifies a translation by the given amount in the X direction. 指定在X方向上给定数量的平移量。
translateY(<length>) specifies a translation by the given amount in the Y direction. 指定在Y方向上给定数量的平移量。
scale(<number>[, <number>]) specifies 2D scaling operation by the [sx,sy]. If sy is not provided, sy will equal sx (growsing or shrinking with the same scale). Scale(1, 1) or scale(1) leaves an element in it’s default state. Scale(2, 2) or scale(2) causes the element to appear twice as wide and twice as tall as its default size, taking up 4-times the original area. 指定[sx,sy]的2D缩放操作。如果不提供sy, sy将等于sx(以相同的比例增长或收缩)。Scale(1,1)或Scale(1)保留元素的默认状态。Scale(2,2)或Scale(2)使元素的宽度和高分别为默认大小的两倍和两倍,占原始区域的4倍。
scaleX(<number>) specifies a scale operation using the [sx, 1] scaling vector, where sx is given as the parameter. 使用[sx, 1]缩放向量指定缩放操作,其中sx作为参数。
scaleY(<number>) specifies a scale operation using the [1, sy] scaling vector, where sy is given as the parameter. 指定使用[1,sy]缩放向量的缩放操作,其中sy作为参数给出。
rotate(<angle>) specifies a 2D rotation by the angle specified in the parameter about the origin of the element, as defined by the transform-origin property. For example, rotate(90deg) would cause elements to appear rotated one-quarter of a turn in the clockwise direction. 根据元素原点参数中指定的角度指定2D旋转,由transform-origin属性定义。例如,旋转(90deg)会使元素以顺时针方向旋转四分之一圈。
skewX(<angle>) specifies a skew transformation along the X axis by the given angle. 指定给定角度沿X轴的倾斜变换。
skewY(<angle>) specifies a skew transformation along the Y axis by the given angle. 指定给定角度沿Y轴的倾斜变换。
matrix(<num>, <num>, <num>, <num>, <num>, <num>) Generally machine generated, specifies a 2D transformation in the form of a transformation matrix of six values. matrix(a,b,c,d,e,f) is equivalent to applying the transformation matrix [a b c d e f]. 一般由机器生成,以六个值的转换矩阵的形式指定二维转换。矩阵(a,b,c,d,e,f)等价于应用变换矩阵**[a b c d e f]*。
Order of transform functions matters: if you rotate first, your translate direction will be on the rotated axis! 转换函数的顺序很重要:如果你先旋转,你的平移方向将在旋转轴上!
3D Transform Functions & Properties
3D Transform Functions
translate(<x-length>[, <y-length>]) specifies a 2D translation by the vector [tx, ty], where tx is the first translation-value parameter and ty is the optional second translation-value parameter. If <ty> is not provided, ty has zero as a value. 通过向量[tx, ty]指定2D转换,其中tx是第一个平动值参数,ty是可选的第二个平动值参数。如果没有提供**<ty>*,则ty的值为0。
translate3d(<x>, <y>, <z>) specifies a 3D translation by the vector [tx,ty,tz], with tx, ty and tz being the first, second and third translation-value parameters respectively. 指定向量[tx,ty,tz]的三维平移,其中tx、ty和tz分别是第一个、第二个和第三个平移值参数。
translateX(<x-length>), translateY(<y-length>) specifies a translation by the given amount in the X or Y direction. 指定在X或Y方向上给定数量的平移量。
translateZ(<z-value>) specifies a translation by the given amount in the Z direction. Note that percentage values are not allowed in the translateZ translation-value, and if present are evaluated as 0. 指定在Z方向上给定数量的平移量。注意,百分比值在translateZ平动值中是不允许的,如果当前值被计算为0。
scale(<number>[, <number>]) specifies a 2D scale operation by the [sx,sy] scaling vector described by the 2 parameters. If the second parameter is not provided, it is takes a value equal to the first. 指定由两个参数描述的[sx,sy]缩放向量进行的2D缩放操作。如果没有提供第二个参数,它将接受一个与第一个相同的值。
scale3d(<number>, <number>, <number>) specifies a 3D scale operation by the [sx,sy,sz] scaling vector described by the 3 parameters. 指定由3个参数描述的[sx,sy,sz]缩放向量进行的三维缩放操作。
scaleX(<number>), scaleY(<number>) specifies a scale operation using the [sx,1,1] or [1,sy,1] scaling vector, where sx or sy is given as the parameter respectively. 指定使用[sx,1,1]或[1,sy,1]缩放向量的缩放操作,其中sx或sy分别作为参数给出。
scaleZ(<number>) specifies a scale operation using the [1,1,sz] scaling vector, where sz is given as the parameter. 使用[1,1,sz]缩放向量指定缩放操作,其中sz作为参数。
rotate(<angle>) specifies a 2D rotation by the angle specified in the parameter about the origin of the element, as defined by the transform-origin property. 根据元素原点参数中指定的角度指定2D旋转,由transform-origin属性定义。
rotate3d(<number>, <number>, <number>, <angle>) specifies a clockwise 3D rotation by the angle specified in last parameter about the [x,y,z] direction vector described by the first 3 parameters. If the direction vector is not of unit length, it will be normalized. A direction vector that cannot be normalized, such as [0, 0, 0], will cause the rotation to not be applied. This function is equivalent to matrix3d(1 + (1-cos(angle))(xx-1), -zsin(angle)+(1-cos(angle))xy, ysin(angle)+(1-cos(angle))xz, 0, zsin(angle)+(1-cos(angle))xy, 1 + (1-cos(angle))(yy-1), -xsin(angle)+(1-cos(angle))yz, 0, -ysin(angle)+(1-cos(angle))xz, xsin(angle)+(1-cos(angle))yz, 1 + (1-cos(angle))(zz-1), 0, 0, 0, 0, 1). 指定按最后一个参数中指定的角度顺时针旋转3D,前三个参数描述的[x,y,z]方向向量。如果方向向量不是单位长度的,它将被归一化。不能归一化的方向向量,如[0,0,0],将导致不应用旋转。这个函数相当于matrix3d (1 + (1-cos(角))(x * x - 1) - z 罪(角)+ (1-cos(角)) x * y, y 罪(角)+ (1-cos(角)) x * z, 0, z 罪(角)+ (1-cos(角)) x * y, 1 + (1-cos(角)) (y * y-1), - x 罪(角)+ (1-cos(角)) y * z, 0, - y 罪(角)+ (1-cos(角))xz,x * sin(角)+ (1-cos(角)) yz, 1 + (1-cos(角))(z * z 1), 0, 0, 0, 0, 1)。
rotateX(<angle>) specifies a clockwise rotation by the given angle about the X axis. 指定绕X轴的给定角度的顺时针旋转。
rotateY(<angle>) specifies a clockwise rotation by the given angle about the Y axis. 指定以给定的角度绕Y轴顺时针旋转。
rotateZ(<angle>) specifies a clockwise rotation by the given angle about the Z axis. 指定绕Z轴的给定角度的顺时针旋转。
skewX(<angle>),skewY(<angle>) specifies a skew transformation along the X axis or Y axis by the given angle. 指定给定角度沿X轴或Y轴的倾斜变换。
skew(<angle> [, <angle>]) specifies a skew transformation along the X and Y axes. The first angle parameter specifies the skew on the X axis. The second angle parameter specifies the skew on the Y axis. If the second parameter is not given then a value of 0 is used for the Y angle (ie. no skew on the Y axis). 指定沿X轴和Y轴的倾斜变换。第一个角参数指定X轴上的倾斜。第二个角参数指定了Y轴上的倾斜。如果没有给出第二个参数,则Y角的值为0(即。Y轴没有倾斜)。
matrix(<number>{6}) specifies a 2D transformation in the form of a transformation matrix of six comma separated values. matrix(a,b,c,d,e,f) is equivalent to matrix3d(a, b, 0, 0, c, d, 0, 0, 0, 0, 1, 0, e, f, 0, 1). 以由六个逗号分隔值组成的转换矩阵的形式指定二维转换。矩阵(a,b,c,d,e,f)等价于矩阵x3d(a, b, 0,0,c,d, 0,0,0,1, 0, e,f, 0,1)
matrix3d(<number>{15}) specifies a 3D transformation as a 4x4 homogeneous matrix of 16 comma separated values in column-major order. 指定一个3D转换为4x4齐次矩阵,其中16个逗号分隔值按列-主顺序排列。
perspective(<number>) specifies a perspective projection matrix. This matrix maps a viewing cube onto a pyramid whose base is infinitely far away from the viewer and whose peak represents the viewer’s position. The viewable area is the region bounded by the four edges of the viewport (the portion of the browser window used for rendering the webpage between the viewer’s position and a point at a distance of infinity from the viewer). The depth, given as the parameter to the function, represents the distance of the z=0 letters from the viewer. Lower values give a more flattened pyramid and therefore a more pronounced perspective effect. The value is given in pixels, so a value of 1000 gives a moderate amount of foreshortening and a value of 200 gives an extreme amount. The matrix is computed by starting with an identity matrix and replacing the value at row 3, column 4 with the value -1/depth. The value for depth must be greater than zero, otherwise the function is invalid. 指定透视投影矩阵。这个矩阵将一个观察立方体映射到一个金字塔上,该金字塔的底部无限远离观察者,其峰值代表观察者的位置。可视区域是由viewport的四条边(浏览器窗口的一部分,用于在查看器的位置和与查看器无限远的点之间呈现页面)所限定的区域。作为函数的参数,depth表示z=0个字母到查看器的距离。数值越低,金字塔越平,透视效果越明显。该值以像素为单位给出,因此值1000表示适度的透视,值200表示极端的透视。矩阵的计算方法是从一个单位矩阵开始,将第3行第4列的值替换为-1/depth。深度值必须大于零,否则函数无效。
3D Transform related Properties
perspective: none | length Same as transforms: perspective(value) except it applies to the positioned or transformed children of the element, not the element itself. 与transforms: perspective(value)相同,但它适用于元素的定位或转换后的子元素,而不是元素本身。
transform-origin: length | keyterm {1,3} The centerpoint of the transform 变换的中心点
transform-style: flat | preserve-3d How to handle nested elements are rendered in 3D space. 如何处理嵌套元素呈现在三维空间。
perspective-origin: pos relative to parent Defines the origin for the perspective property. It effectively sets the X and Y position at which the viewer appears to be looking at the children of the element. 定义透视图属性的原点。它有效地设置了X和Y的位置,在这个位置上,查看器似乎正在查看元素的子元素。
backface-visibility: visible | hidden When an element is flipped, is the content that is flipped away from user visible or not. 当元素被翻转时,是从用户可见或不可见的角度翻转的内容。
Perspective & Perspective Origin
Perspective
Screens are flat. 3D requires perspective.
transform: perspective(100) …
perspective: 100
Difference: with the parent property, all the transformed elements share the same perspective. with the function, each transformed element has it’s own perspective. 区别:使用父属性,所有转换后的元素共享同一个透视图。使用该函数,每个转换后的元素都有自己的透视图。
Transform Function: perspective()
1
transform: perspective(40px) rotateX(10deg)
The perspective() function must come first Smaller numbers have a bigger impact
Future: Defines the layout box, to which the transform and transform-origin properties relate to. (FF, Ch 64, O 51) Future:定义与transform和transform-origin属性相关的布局框。(FF, Ch 64, O 51)
border-box border box as reference box.
fill-box Uses the object bounding box as reference box.
view-box Nearest SVG viewport as reference box. If viewBox attribute exists, the reference box is at the viewBox 0 0, and the width and height are those of the viewBox attribute.
html { font-size: 62.5%; } p { font-size: 13px; font-size: 1.3rem; } small { font-size: 11px; font-size: 1.1rem; }
viewport width
vw | vh | vmin | vmax 5vw = 5% of the width of the viewport 7vh = 7% of the height of the viewport 4vmin = 4% of the viewport height or width, whichever is smaller 8vmax = 8% of the viewport height or width, whichever is larger
under consideration vi 1% of containing block, in the direction of the root element’s inline axis.
vb 1% of the containing block, in the direction of the root element’s block axis.
Pointer Events & Content Editable
pointer-events: none
Can the element be clicked?!?!
1 2 3
.animatedElement { pointer-events: none; }
Did you note that you could change the transforms examples even when the example was covering the code?
-webkit-user-modify
Related to contentEditable: Determines whether content of an element is editable. 与contenttEditable相关:确定元素的内容是否可编辑。