Css3 新增的属性以及使用

Css3基础操作

 . Css3?

css3事css的最新版本

width. heith.background.border**都是属于css2.1
CSS3会保留之前 CSS2.1的内容,只是添加了一些新的语法。
CSS3 : border-radius :nth-of-type() background-size**

## 1.transition过渡?
.transition-property : 规定设置过渡效果的CSS属性的名称。
all ( 默认值 ) , 指定 width , height;
.transition-duration :规定完成过渡效果需要多少秒或毫秒。
需要添加单位:s (秒) ms (毫秒) 1s == 1000ms
transition-delay : 定义过渡效果何时开始。
2s : 延迟两秒进行过渡
-2s : 提前两秒进行过渡
transition-timing-function: 规定速度效果的速度曲线。
运动形式:加速、减速、匀速...
linear(匀速)
ease(默认值)
ease-in(加速)
ease-out(减速)
ease-in-out(先加速后减速)
复合写法:
transition:all 2s linear;
transition:linear 2s all;
transition:2s linear all;
注意:当总时间与延迟时间同时存在的时候,就有顺序了,第一个是总时间,第二个是延迟时间。

transition:2s 3s linear all; 3s表示延迟时间在开始运动

<style>
#box{ width:100px; height: 100px; background:red;
transition-duration : 2s;
transition-timing-function: linear; }
#box:hover{ width:200px; height: 200px; background: blue;}
</style>
</head>
<div id="box"></div>

</body>
</html>
代码在这里可以试试

3. transform变形?
translate : 位移
transform:translate(100px,100px); : 两个值 分别对应 x 和 y。
transform:translateX(100px);
transform:translateY(100px);
transform:translateZ(100px); ( 3d )

<style>
*{ margin:0px; padding:0;}
body{ height:2000px;}
#share{ width:300px; height:300px; background:red; position: fixed;
left: -300px; top:50%; margin-top:-150px;
transition:1s;
}
share div{ width:30px; height: 100px; background:blue; position:absolute;
right:-30px; top:0;
color:white; font-size:30px;
}
share:hover{ left:0;}
</style>
</head>
<body>
<div id="share">
<div>分享</div>
</div>
</body>
</html>

**scale : 缩放**
transform:scale(num) num是一个比例值,正常比例是1。
transform:scale(num1 , num2) 两个值 分别对应 w 和 h
transform:scaleX()
transform:scaleY()
transform:scaleZ() ( 3d )


<style>
#box{ width:538px; height:414px; overflow: hidden;}
#box img{ transition: .5s linear;}
#box:hover img{ transform:scale(1.3);}
</style>
</head>
<body>
<div id="box">
<img src="./wys.jpg" >
</div>
</body>

**rotate : 旋转**
transform:rotate(num) num是旋转的角度 30deg
正值:顺时针旋转
负值:逆时针旋转
表示一个角:角度deg 或 弧度rad

rotateX() ( 3d )
rotateY() ( 3d )
rotateZ()

<style>
#box1{ width:300px; height: 300px; border:1px black solid; margin:30px auto;}
#box2{ width:100px; height:100px; background:red; transition: 1s;
transform-origin: 150px 150px;
}
#box1:hover #box2{ transform:rotate(180deg);}

</style>
</head>
<body>
<div id="box1">
<div id="box2">bbbbb</div>
</div>
</body>
</html>

**skew : 斜切**
transform:skew(num1,num2) : num1和num2都是角度,针对的是x 和 y
transform:skewX()
transform:skewY()
注:skew没有3d写法。

注:所有的变形操作,都不会影响到其他元素。(类似于相对定位)
注:变形操作对inline(内联元素)不起作用的。
注:transform可以同时设置多个值。
先执行后面的操作,在执行前面的操作。
位移会受到后面要执行的缩放、旋转和斜切的影响。

## 4. tranform-origin 基点位置 ?

主要是针对 旋转和缩放,默认都是中心点为基点。
left 左 right右

## 5. animation动画?

原理:逐帧动画。会把整个运动过程,划分成100份。

**animation-name :** 设置动画的名字 (自定义的)
**animation-duration :** 动画的持续时间
**animation-delay :** 动画的延迟时间
**animation-iteration-count :** 动画的重复次数 ,默认值就是1 ,infinite无限次数
**animation-timing-function :** 动画的运动形式
**ease linear**

**@keyframes 动画的名字 {
from {}
to {}
}**
**from : 起点位置 , 等价于 0% to : 终点位置 ,等价于 100%**

动漫扩展

<style>
#box{width:100px; height:100px; background:red; margin:10px;
animation: 3s move infinite;
animation-direction: alternate;
}
@keyframes move {
0%{ transform:translate(0,0);}
100%{ transform:translate(400px,0)}
}
</style>
</head>
<body>
<!-- <div id="box1"></div>
<div id="box2"></div>
<div id="box3"></div>
<div id="box4"></div> -->
<div id="box"></div>
</body>
</html>

## 复合样式:

**animation**

**animation-fill-mode :** 规定动画播放之前或之后,其动画效果是否可见。
**none (默认值) :** 在运动结束之后回到初始位置,在延迟的情况下,让0%在延迟后生效
**backwards :** 在延迟的情况下,让0%在延迟前生效
**forwards :** 在运动结束的之后,停到结束位置
**both :** backwards和forwards同时生效

**animation-direction :** 属性定义是否应该轮流反向播放动画。
**alternate :** 一次正向(0%~100%),一次反向(100%~0%)
**reverse :** 永远都是反向 , 从100%~0%
**normal** (默认值) : 永远都是正向 , 从0%~100%

## 6. 3D效果?

**perspectve(景深) :** 离屏幕多远的距离去观察元素,值越大幅度越小。
3D的眼镜

rotateX
rotateY
translateZ
scaleZ

注:反馈回来的立体,仅限于平面。

**transform-style :** 3D空间
flat (默认值2d)、preserve-3d (3d,产生一个三维空间)

注:只要是有厚度的立体图形,就必须添加3D控件。

注:在立方体中默认会沿着第一个面进行旋转。
**tranform-origin : x y z;** (z不能写单词,只能写数字)

**perspective-origin :** 景深-基点位置,观察元素的角度。

**backface-visibility :** 背面隐藏
**hidden、visible** (默认值)

**3D正方体写法**

<style>
*{ margin:0; padding:0;}
ul{ list-style: none;}
#box{ width:300px; height: 300px; border:1px black solid; margin:30px auto;
perspective: 500px;
}
#box ul{ width:100px; height:100px; margin:100px; position: relative;
transition: 4s;
transform-style: preserve-3d;
}
#box ul li{ width:100%; height: 100%; position: absolute; left:0; top:0; text-align: center; line-height: 100px; font-size:30px;}
#box ul li:nth-of-type(1){ background:red;}
#box ul li:nth-of-type(2){ background:blue; left:100px;
transform-origin:left; transform:rotateY(90deg);}
#box ul li:nth-of-type(3){ background:green; left:-100px;
transform-origin:right; transform:rotateY(-90deg);
}
#box ul li:nth-of-type(4){ background:hotpink; top:-100px;
transform-origin:bottom; transform:rotateX(90deg);
}
#box ul li:nth-of-type(5){ background:gray; top:100px;
transform-origin:top; transform:rotateX(-90deg);
}
#box ul li:nth-of-type(6){ background:yellow;
transform:translateZ(-100px) rotateY(180deg);
}
#box:hover ul{ transform:rotateY(360deg); }
</style>
</head>
<body>
<div id="box">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>
</div>
</body>
</html>

### 3d写法( 扩展学习 )

scale3d() : 三个值 x y z
translate3d() : 三个值 x y z
rotate3d() : 四个值 0|1(x轴是否添加旋转角度) 0|1(y轴是否添加旋转角度) 0|1(z轴是否添加旋转角度) deg
rotate3d(1,1,1,30deg);
scale translate skew

## 7. background-origin : 背景图的填充位置


1.默认情况下,如果xy都平铺的话,border padding content 区域都有背景图。

padding-box (默认) : 在padding区域开始填充背景图
border-box : 在border区域开始填充背景图
content-box : 在content区域开始填充背景图

2. background-clip : 背景图的裁切方式

padding-box
border-box (默认)
content-box

注:当位置与裁切写入复合样式中,那么第一个值表示位置,第二个值表示裁切。

背景图的填充

<style>
#box{ width:400px; height:400px; border:50px rgba(255,0,0,.5) solid; background:url(‘./laoli.jpg‘) padding-box content-box; padding:50px; color:white;
/* background-origin: border-box; */
/* background-origin: content-box;
background-clip: content-box; */
}
</style>
</head>
<body>
<div id="box">我是content部分</div>
</body>
</html>


## 8. CSS3渐变?

线性渐变:
background-image:linear-gradient( 20deg , red , blue);
注:角度是0deg在容器的最下面bottom位置。正数就是顺时针旋转。

径向渐变:
radial-gradient : 径向渐变

CSS3渐变

<style>
#box{ width:300px; height:40px; border:1px black solid; margin:50px;
background-image:linear-gradient( to right top, green 25% , gray 25%, gray 50% , green 50% , green 75%, gray 75%);
background-size:40px 40px;
animation: infinite linear 3s move;
}
@keyframes move {
0%{ background-position: 0 0;}
100%{ background-position: 400px 0;}
}
</style>
</head>
<body>
<div id="box"></div>
</body>
</html>

逆战班 

 

相关推荐