CSS3 Logo

CSS3 介绍

Flexible Box Layout

弹性盒模型

display: box

特点:

<div class="wrap">
    <div class="box1">1</div>
    <div class="box2">2</div>
    <div class="box3">3</div>
</div>

box-orient

设置弹性盒模型对象的子元素的排列方式。

取值:
1
2
3

box-pack

设置弹性盒模型对象的子元素的排列方式。

取值:
1
2
3

box-align

设置弹性盒模型对象的子元素的排列方式。

取值:
1
2
3

box-flex

设置弹性盒模型对象的子元素如何分配其剩余空间。

取值:<number>
1
2
3

box-ordinal-group

设置弹性盒模型对象的子元素的显示顺序。

取值:<integer>
1
2
3

box-direction

设置弹性盒模型对象的子元素的排列顺序是否反转。

取值:
1
2
3

box-lines

设置弹性盒模型对象的子元素是否可以换行显示。

取值:

single(默认) | multiple


box-flex-group

设置弹性盒模型对象的子元素的所属组。

取值:<integer>

PS: 以上2个目前都未实现

Border

边框

border-radius ( 圆角 )

基本语法:水平与垂直半径相同时
border-radius: 10px;

长度值:

百分比:

border-radius ( 圆角边框 )

基本语法:水平与垂直半径相同时

border-radius: 10px 30px

border-radius: 10px 30px 50px

border-radius: 10px 30px 70px 50px

border-radius ( 圆角边框 )

基本语法:水平与垂直半径不同时
border-radius: 水平半径{1,4} / 垂直半径{1,4}

border-radius: 60px / 30px

border-radius: 10px 50px / 20px 40px 60px 80px

border-radius ( 圆角边框 )

拆分语法:
border-top-left-radius: 20px;
border-top-right-radius: 80px 40px;
border-bottom-left-radius: 30px;
border-bottom-right-radius: 70px;

✍画个鸡蛋?



border-radius: 50% / 65% 65% 35% 35%;

border-image ( 图像边框 )


border-image:url(res/border.png) 27 27 27 27 / 27px 27px 27px 27px repeat

裁剪区域:
上:
右:
下:
左:
边框宽度:
上:
右:
下:
左:
填充方式:

box-shadow ( 盒阴影 )

box-shadow: 0 5px 20px 0 red

水平偏移:

垂直偏移:

模糊半径:

阴影扩展:

Gradient

渐变

linear-gradient() (线性渐变)

radial-gradient() ( 径向渐变 )

repeating-linear-gradient()
( 重复线性渐变 )

repeating-linear-gradient(-90deg,#fff, olive 20%)

repeating-radial-gradient()
( 重复径向渐变 )

repeating-radial-gradient(circle cover,#fff,orange 20%)

✍画条彩虹?


background-image: radial-gradient(
  50% 110%,    ellipse farthest-side,
  white 56%,   #FF4D4D 59%, #FFA64D 62%, #FFDC73 65%,
  #93FF26 68%, #4DFFFF 71%, #2693FF 74%, #D24DFF 77%,
  white 80%);
Background

背景

background-image

background: -webkit-linear-gradient(#fff, olive);
background: -moz-linear-gradient(#fff, olive);
background: -ms-linear-gradient(#fff, olive);
background: -o-linear-gradient(#fff, olive);
background: linear-gradient(#fff, olive);

background-attachment

设置背景图像是随对象内容滚动还是固定的。

border: 2px solid #333;
height: 200px;
overflow: auto;
background: url(res/icon.png) no-repeat 50% top;
scroll(默认) fixed local(CSS3)
  • 001
  • 002
  • 003
  • 004
  • 005
  • 006
  • 007
  • 008
  • 009
  • 010
  • 011
  • 012
  • 013
  • 014
  • 015
  • 016
  • 017
  • 018
  • 019
  • 020
  • 001
  • 002
  • 003
  • 004
  • 005
  • 006
  • 007
  • 008
  • 009
  • 010
  • 011
  • 012
  • 013
  • 014
  • 015
  • 016
  • 017
  • 018
  • 019
  • 020
  • 001
  • 002
  • 003
  • 004
  • 005
  • 006
  • 007
  • 008
  • 009
  • 010
  • 011
  • 012
  • 013
  • 014
  • 015
  • 016
  • 017
  • 018
  • 019
  • 020

background-repeat

设置对象的背景图像如何铺排填充。

border: 2px solid #333;
height: 240px;
background: url(res/icon.png) no-repeat 0 0;
repeat(默认) round(CSS3) space(CSS3)

background-origin

设置对象的背景图像background-position的原点(位置)。

border: 10px solid rgba(0,0,0,.5);
padding: 20px;
height: 160px;
background: url(res/icon.png) no-repeat 0 0;
padding-box(默认) border-box content-box
content
content
content

background-size

设设置对象的背景图像的尺寸大小。

border: 10px solid rgba(0,0,0,.5);
padding: 20px;
height: 120px;
background: url(res/icon.png) no-repeat 0 0;
auto(默认) 50px 80% cover contain
content
content
content
content

background-clip

设置指定对象的背景图像向外裁剪的区域。

border: 10px solid rgba(0,0,0,.5);
padding: 20px;
height: 80px;
background: url(res/icon.png) no-repeat 0 0;
background-size: 64px;
background-origin: border-box;
border-box(默认) padding-box content-box
content
content
content

Multiple background

设置对象的多重背景图像(background-color不能设置多重)。

height: 200px;
border: 2px solid #333;
background:url(res/logo.png) no-repeat center,
           linear-gradient(#fff,rgba(255,255,255,.5)),
           skyblue;
background-size: 128px 128px, 100% 50%, 100% 100%;
User Interface

用户界面

box-sizing

width: 200px;
height: 200px;
padding: 20px;
border: 10px solid red;
content-box(默认) border-box

resize

设置对象是否允许用户缩放,调节元素尺寸大小。

如果希望此属性生效,需要设置对象的overflow属性,值可以是auto,hidden或scroll。

none(默认) both horizontal vertical

ime-mode

设置是否允许用户激活输入中文,韩文,日文等的输入法(IME)状态。

auto(默认) disabled
文本框: 文本框:
Multi-column

多列

columns

columns: 200px
7.1. The length of columns

What happens when the 'height' property is non-auto? Are column lengths in any way constrained by the 'height' property? Two options seems possible:
Similarly, the 'max-height' and 'min-height' properties must be described. Another option is to create 'column-length' property.

7.2. Absolutely positioned elements in columns

What is the desired behaviour when an element in a column is an absolute container (e.g., relatively positioned)? In particular, do its absolutely positioned children break at column boundaries too? A similar question arises for pages and the fact that we don't currently break abs-pos children across page boundaries is a huge source of complaints, so I strongly push for abs-pos children to break at column boundaries, and I'd like as much guidance as possible as to the preferred behaviour. Do consider what happens if the in-flow content fits in N columns but additional columns would be required to fit abs-pos content.

宽度:

列数:

column-width

设置对象每列的宽度

column-width: 200px

column-count

设置对象每列的列数

column-count: 4

column-rule

设置对象的列与列之间的边框,参阅border属性。

column-rule: 5px dashed blue
7.1. The length of columns

What happens when the 'height' property is non-auto? Are column lengths in any way constrained by the 'height' property? Two options seems possible:
Similarly, the 'max-height' and 'min-height' properties must be described. Another option is to create 'column-length' property.

7.2. Absolutely positioned elements in columns

What is the desired behaviour when an element in a column is an absolute container (e.g., relatively positioned)? In particular, do its absolutely positioned children break at column boundaries too? A similar question arises for pages and the fact that we don't currently break abs-pos children across page boundaries is a huge source of complaints, so I strongly push for abs-pos children to break at column boundaries, and I'd like as much guidance as possible as to the preferred behaviour. Do consider what happens if the in-flow content fits in N columns but additional columns would be required to fit abs-pos content.

column-gap

column-gap: 50px
7.1. The length of columns

What happens when the 'height' property is non-auto? Are column lengths in any way constrained by the 'height' property? Two options seems possible:
Similarly, the 'max-height' and 'min-height' properties must be described. Another option is to create 'column-length' property.

7.2. Absolutely positioned elements in columns

What is the desired behaviour when an element in a column is an absolute container (e.g., relatively positioned)? In particular, do its absolutely positioned children break at column boundaries too? A similar question arises for pages and the fact that we don't currently break abs-pos children across page boundaries is a huge source of complaints, so I strongly push for abs-pos children to break at column boundaries, and I'd like as much guidance as possible as to the preferred behaviour. Do consider what happens if the in-flow content fits in N columns but additional columns would be required to fit abs-pos content.

列间距:

column-span

column-span: all
7.1. The length of columns

What happens when the 'height' property is non-auto? Are column lengths in any way constrained by the 'height' property? Two options seems possible:
Similarly, the 'max-height' and 'min-height' properties must be described. Another option is to create 'column-length' property.

我是一个大标题

7.2. Absolutely positioned elements in columns

What is the desired behaviour when an element in a column is an absolute container (e.g., relatively positioned)? In particular, do its absolutely positioned children break at column boundaries too? A similar question arises for pages and the fact that we don't currently break abs-pos children across page boundaries is a huge source of complaints, so I strongly push for abs-pos children to break at column boundaries, and I'd like as much guidance as possible as to the preferred behaviour. Do consider what happens if the in-flow content fits in N columns but additional columns would be required to fit abs-pos content.

column-break-before

设置对象之前是否断行。

7.1. The length of columns

What happens when the 'height' property is non-auto? Are column lengths in any way constrained by the 'height' property? Two options seems possible:
Similarly, the 'max-height' and 'min-height' properties must be described.

7.2. Absolutely positioned elements in columns

What is the desired behaviour when an element in a column is an absolute container?

7.3. Floating elements in columns

When an element that forms a stacking context (e.g. abs-pos with z-index not 'auto', or 'opacity' not 1) breaks vertically, do the pieces together still form a single stacking context? This could get hard to implement in general.

column-break-after

设置对象之后是否断行。

取值:auto | always | avoid

column-break-inside

设置对象内部是否断行。

取值:auto | avoid
Pseudo-Classes Selectors

伪类选择符

E:nth-child(n)

<ul class="balls balls-1">
    <li>1</li>...<li>10</li>
</ul>

E:nth-last-child(n)

<ul class="balls balls-2">
    <li>1</li>...<li>10</li>
</ul>

E:only-child

.balls > li:only-child { ... }
<ul class="balls">
    <li>1</li>
</ul>
<ul class="balls">
    <li>1</li><li>2</li><li>3</li>
</ul>

E:first-child

.balls > li:first-child { ... }




E:last-child

.balls > li:last-child { ... }

type 系列

div.test
div1

p1

div2
div3

状态 系列

  • 启用状态
  • 启用状态
  • 启用状态
  • 禁用状态
  • 禁用状态

E:not()

匹配不含有s选择符的元素E。



E:root

匹配E元素在文档的根元素。在HTML中,根元素永远是HTML。


E:empty

匹配没有任何子元素(包括text节点)的元素E。


E:target

匹配相关URL指向的E元素。

✍该怎么选?

选择前4个元素

.balls > li:nth-child(-n+4) { ... }

从第一个开始,选择每第四个

.balls > li:nth-child(4n+1) { ... }
Units

单位

长度 (Length)

rem
相对长度单位,相对于根元素(即html元素)font-size计算值的倍数。

html->32px

font-size:0.5em font-size:2em

font-size:0.5em font-size:2rem

角度 (Angel)

90deg = 100grad = 0.25turn ≈ 1.570796326794897rad

deg
度(Degress)。一个圆共360度
grad
梯度(Gradians)。一个圆共400梯度
turn
转、圈(Turns)。一个圆共1圈
rad
弧度(Radians)。一个圆共2π弧度
Transform

转换

scale()

取值:<x:number>[,<y:number>]
scale(1, 1)

X:

Y:

scaleX() scaleY()

以下三种语法效果一样

transform: scale(2);
transform: scale(2, 2);
transform: scaleX(2) scaleY(2);

translate()

取值:<x:length>[,<y:length>]
translate(0, 0)

X:

Y:

translateX() translateY()

以下两种语法效果一样

transform: translate(100px, 100%);
transform: translateX(100px) translateY(100%);

transform: translate(100%);

skew()

取值:<x:angel>[,<y:angel>]
skew(0, 0)

X:

Y:

skewX() skewY()

以下两种语法效果一样

transform: skew(100deg, 100deg);
transform: skewX(100deg) skewY(100deg);

transform: skew(100deg);

rotate()

取值:<angel>
rotate(0)

Angel:

matrix()

取值:<number>,<number>,<number>,<number>,<number>,<number>

矩阵。。。

transform-origin

取值:x: <percentage> | <length> | left | center | right
   y: <percentage> | <length> | top | center | bottom
transfarm: scale(1.5);
50% 50%(默认) top left bottom center

transform语法

transform: rotate(30deg) scale(1.5) skew(10deg, 50deg);
transform-origin: top left;
Transition

过渡

transition

div {
   transition: transform ease-in .5s;
}
div:hover {
   transform: scale(2);
}

transition-property

设置对象中的参与过渡的属性。

transition-property: all; /*默认*/
transition-property: none;
transition-property: background-color;
transition-property: background-color, height, width;

~所有动画属性列表

transition-duration

设置对象过渡的持续时间。

transition-duration: 2s;
transition-duration: 4000ms;
transition-duration: 4000ms, 8000ms;

transition-timing-function

设置对象中过渡的类型。

ease(默认)
linear
ease-in
ease-out
ease-in-out

transition-timing-function

取值:cubic-bezier(P1x, P1y, P2x, P1y)

ease-in-out: 由慢到快再到慢→贝塞尔曲线(0.42, 0, 0.58, 1.0)

transition-delay

设置对象延迟过渡的时间。

0(默认)
1s
2000ms
-3s

transition

复合语法

transition: width 3s, height 2s 2s;
transition: background-color 3s linear 1s;
transition: 4s ease-in-out;
transition: 5s;
Animation

动画

animation

div:hover i {
    animation: loading 3s ease-out infinite
}
@keyframes loading{
    0% { width: 0 }
    100% { width: 100% }
}

↑ 鼠标移上去 ↑

animation 独立属性

div {
    animation: name 3s ease 1s 3 alternate;
}
that's all

Thanks ☺

返回首页 »

快捷键

铺满窗口:
W
窗口适配:
S
全屏模式:
F
切换主题:
T
上一页:
↑ / ← / P / PageDown
下一页:
↓ / → / N / PageUp / Space
第一页:
Home
最后一页:
End
画笔:
Ctrl+鼠标左键
荧光笔:
Alt+鼠标左键
点击任意区域退出
加载中...