Day7——CSS3的简单基础

前言:此文章为在校期间老师所授,记录着课堂知识。

过渡

盒子 位置

<style type="text/css">
			
			div{
				width: 100px;
				height: 100px;
				background-color: pink;
				
				
			}
			
			
			div:hover{
				width: 500px;
				height: 500px;
				
			}
			
		</style>

先不加过渡,然后运行起来就是本来100x100大小,鼠标移上去瞬间500x500.

	transition:all 5s;

在div下加入这个就会变成鼠标移上去,从100x100到500x500花费5秒缓慢张开。

			div{
				width: 100px;
				height: 100px;
				background-color: pink;
				transition: width 5s ease 1s ,height 3s; 
				/* 参与过度的属性,完成过度的时间,完成过度的类型,延迟时间 */
				
			}

颜色

		<style type="text/css">
			
			div{
				width: 100px;
				height: 100px;
				background-color: pink;
				transition: width 5s ease-out 1s ,height 3s,
				background-color .5s ease-in .1s; 
				
				
				
			}
			
			
			div:hover{
				width: 500px;
				height: 500px;
				background-color:#bbb;
				
			}
			
		</style>

鼠标移上去变色,在div里加入background-color 即可。
然后在下面的hover那里把要变的颜色加上。

另外还有渐变色。
background: linear-gradient(to right,#fe6785,#fca6aa);
to right 是从左到右进行渐变色
to bottom 是从上到下进行渐变色设置

图片左右移动

		<style type="text/css">
			div{
				width: 600px;
				height: 300px;
				border: 1px solid red;
				overflow: hidden;
			}
			div img{
				width: 300px;
				height: 300px;
				transition: all 0.5s;
			}
			div:hover img{
				margin-left: 300px;
			}
		</style>

...

		<body>
			<div>
				<img src="img/lf.png" />
			</div>
		</body>

在下面插入图片,然后让图片移动的话,要在图片的div img下面设置transition。
在hover里面设置位移的方向距离。

放大缩小

		<style type="text/css">
			div{
				width: 200px;
				height: 200px;
				background-color: #FFC0CB;
				transition: all 3s;
			}
			div:hover{
				/* 大于1,放大,小于1,缩小 */
				/* X轴宽度,Y轴高度 */
				transform: scale(0.8,1.2);
			}
		</style>

...

		<body>
		
			<div></div>
			
		</body>

在hover加入transform:scale即可,若只有一个参数,那么就是放大或缩小。
两个参数就是宽度和高度。

图片缩放

	<style type="text/css">
		div{
			margin-top: 200px;
			margin-left: 200px;
			width: 200px;
			height: 200px;
			background-color: #FFC0CB;
			
		}
		div img{
			width: 200px;
			height: 200px;
			transition: all 0.5s;
			
		}
		div img:hover{
			
			transform: scale(2);
		}
	</style>
	<body>
		
		<div><img src="img/lf.png"></div>
		
	</body>

和之前盒子缩放大同小异…

位移

		<style type="text/css">
			div{
				width: 100px;
				height: 100px;
				background-color: pink;
				transition: all 5s;
				margin-top: 200px;
			}
			div:hover{
				/* transform: translate(100px,100px); */
				/* transform: translateX(100px) */ /* x坐标平移; */
				transform: translateY(-100px);
			}
			
				
			</style>

两个参数就(X方向位移,Y方向位移)。

旋转

		<style type="text/css">
			
			div{
				width: 100px;
				height: 100px;
				background-color: #f153ff;
				margin: 200px auto;
				transition: all 3s;
				
			}
			div:hover{
				transform: rotate(360deg);
			}
			
			
		</style>

div上面没变,只变了hover,改为transform:rotate(360deg)。
设置旋转的原点:

	transform-origin:top left; 

若旋转物100x100,设为中心还可以:

	transform-origin:50px 50px; 
	transform-origin:center; 

展开旋转

<style type="text/css">
			
			div img{
				width: 225px;
				height: 150px;
				
				position: absolute;
				margin-top:300px ;
				margin-left: 300px;
				transition: all 2s;
				transform-origin:top right; 
			}
			
			div:hover img:nth-child(6){
				transform: rotate(360deg);
			}
			div:hover img:nth-child(5){
				transform: rotate(300deg);
			}
			div:hover img:nth-child(4){
				transform: rotate(240deg);
			}
			div:hover img:nth-child(3){
				transform: rotate(180deg);
			}
			div:hover img:nth-child(2){
				transform: rotate(120deg);
			}
			div:hover img:nth-child(1){
				transform: rotate(60deg);
			}
			
			
		</style>
	<body>
		
		<div>
			<img src="img/1.jpg">
			<img src="img/2.jpg">
			<img src="img/3.jpg">
			<img src="img/4.jpg">
			<img src="img/5.jpg">
			<img src="img/6.jpg">
		</div>
		
	</body>

在这里插入图片描述
div:hover img:nth-child(1){
transform: rotate(60deg);
}
鼠标移上去之后,第1个图片旋转60度。

倾斜

		<style type="text/css">
			
			div{
				width: 100px;
				height: 100px;
				margin: 300px auto;
				background-color: #FFC0CB;
				/* transform: skew(60deg); */
				/* transform: skewX(60deg); */
				/* transform: skewY(60deg); */
				transform: skew(60deg);
				
				
			}
			
		</style>

transform:skew 倾斜。
skewX,X轴不变,Y轴偏移。
skewY,Y轴不变,X轴偏移。
只写skew并且后面参数只有一个,默认skewX。
skew(30deg,30deg)就是这样:
在这里插入图片描述

一个30deg,一个60deg就是直线了,不显示了。
加上hover可以更清楚看到变化过程:

		<style type="text/css">
			
			div{
				width: 100px;
				height: 100px;
				margin: 300px auto;
				background-color: #FFC0CB;
				/* transform: skew(60deg); */
				/* transform: skewX(60deg); */
				/* transform: skewY(60deg); */
				
				
				
			}
			div:hover{
				transition: all 3s;
				transform: skew(30deg,60deg);
				
			}
			
			
		</style>

垂直居中

		<style type="text/css">
			div{
				width: 100px;
				height: 100px;
				background-color: #FFC0CB;
				position: absolute;
				top:50%;
				left:50%;
				transform: translate(-50%,-50%);
			}
		</style>

在Day5里面,曾经也使用过垂直居中,这算是第二种方法了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值