CSS属性其他小案例

CSS小案例


运动的汽车

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
        img {
        	animation: move 5s infinite;
        }
        /*定义动画*/
	   @keyframes move {
           0% {
           	  transform: translate3d(0,0,0);
           }
           50% {
           	  transform: translate3d(800px,0,0);
           }
           51% {
           	  /*多组变形 空格隔开即可*/
           	  transform: translate3d(800px,0,0) rotateY(180deg);
           }
           100% {
           	  transform: translate3d(0,0,0) rotateY(180deg);
           }
	   }
	</style>
</head>
<body>
	<img src="car.jpg" alt="" width="100" />
</body>
</html>
返回顶层目录

无缝滚动

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
	   * {
	   	  padding: 0;
	   	  margin: 0;
	   }

	   ul {
	   	  list-style: none;
	   }

	   img {
	   	  display: block;
	   }

	   section {
	   	   width: 378px;
	   	   height: 86px;
	   	   margin: 100px auto;
	   	   overflow: hidden;
	   }

	   section ul {
	   	   width: 1000%;
	   	   animation: moving 5s linear infinite;
	   }

	   ul li {
	   	  float: left;
	   }

	   /*定义动画*/
	   @keyframes moving {
	   	   from {
               transform: translateX(0);
	   	   }
	   	   to {
              transform: translateX(-882px); 
	   	   } 
	   }

	   section:hover ul {
	   	   /* 鼠标放到section时候让ul的动画暂停*/
	   	   animation-play-state: paused;
	   }
	</style>  
</head>
<body>
	<section>
		<ul>
			<li><img src="nav1.jpg" alt=""></li>
			<li><img src="nav2.jpg" alt=""></li>
			<li><img src="nav3.jpg" alt=""></li>
			<li><img src="nav4.jpg" alt=""></li>
			<li><img src="nav5.jpg" alt=""></li>
			<li><img src="nav6.jpg" alt=""></li>
			<li><img src="nav7.jpg" alt=""></li>
			<li><img src="nav1.jpg" alt=""></li>
			<li><img src="nav2.jpg" alt=""></li>
			<li><img src="nav3.jpg" alt=""></li>
		</ul>
	</section>
</body>
</html>
返回顶层目录

传统三等分

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
	   section {
	   	  width: 80%; 
	   	  height: 200px;
	   	  margin: 100px auto;
	   	  border: 1px solid #ccc;
	   }

	   section div{
          width: 33.33%; 
          height: 100%;
          float: left;
	   }

	   div:nth-child(1) {
	   	  background-color: pink;
	   }

	   div:nth-child(2) {
	   	  background-color: red;
	   }

	   div:nth-child(3) {
	   	  background-color: blue;
	   }
	</style>
</head>
<body>
	<section>
		<div></div>
		<div></div>
		<div></div>
	</section>
</body>
</html>
返回顶层目录

伸缩布局实现三等分

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
	   section {
	   	  width: 80%; 
	   	  height: 200px;
	   	  margin: 100px auto;
	   	  border: 1px solid #ccc;
	   	  /*父盒子添加flex*/
	   	  display: flex; /*伸缩布局模式 这个盒子具有弹性*/
	   }

	   section div{
          height: 100%;
          flex: 1; /*子元素添加份数*/
	   }

	   div:nth-child(1) {
	   	  background-color: pink;
	   	  flex: 2;
	   	  order: 10;
	   }

	   div:nth-child(2) {
	   	  background-color: red;
	   	  order: -2;
	   }

	   div:nth-child(3) {
	   	  background-color: blue;
	      order: -1;
	   }
	</style>
</head>
<body>
	<section>
		<div></div>
		<div></div>
		<div></div>
	</section>
</body>
</html>
返回顶层目录

伸缩布局实现固定高度

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
	   section {
	   	  width: 80%; 
	   	  height: 200px;
	   	  margin: 100px auto;
	   	  border: 1px solid #ccc;
	   	  /*父盒子添加flex*/
	   	  display: flex; /*伸缩布局模式 这个盒子具有弹性*/
	   	  min-width: 500px;
	   }

	   section div{
          height: 100%;
	   }

	   div:nth-child(1) {
	   	  background-color: pink;
	   	  width: 200px;
	   }

	   div:nth-child(2) {
	   	  background-color: red;
	   	  width: 100px;
	   }

	   div:nth-child(3) {
	   	  background-color: blue;
	   	  flex: 1;
	   }

	   div:nth-child(4) {
	   	  background-color: green;
	   	  flex: 1;
	   }
	</style>
</head>
<body>
	<section>
		<div>111</div>
		<div>222</div>
		<div>3333</div>
		<div>4444</div>
	</section>
</body>
</html>
返回顶层目录

伸缩布局实现排列方式

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
	   section {
	   	  width: 80%; 
	   	  height: 200px;
	   	  margin: 100px auto;
	   	  border: 1px solid #ccc;
	   	  /*父盒子添加flex*/
	   	  display: flex; /*伸缩布局模式 这个盒子具有弹性*/
	   	  min-width: 500px;
	   	  flex-direction: row-reverse;
	   	  flex-direction: column-reverse;
	   }

	   section div{
         
	   }

	   div:nth-child(1) {
	   	  background-color: pink;
	   	  width: 200px;
	   }

	   div:nth-child(2) {
	   	  background-color: red;
	   	  width: 100px;
	   	  margin: 0 6px;
	   }

	   div:nth-child(3) {
	   	  background-color: blue;
	   	  flex: 1;
	   }

	   div:nth-child(4) {
	   	  background-color: green;
	   	  flex: 1;
	   }
	</style>
</head>
<body>
	<section>
		<div>111</div>
		<div>222</div>
		<div>3333</div>
		<div>4444</div>
	</section>
</body>
</html>
返回顶层目录

justify-content属性

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
	   section {
	   	  width: 80%; 
	   	  height: 200px;
	   	  margin: 100px auto;
	   	  border: 1px solid #ccc;
	   	  /*父盒子添加flex*/
	   	  display: flex; /*伸缩布局模式 这个盒子具有弹性*/
	   	  min-width: 500px;
	   	  justify-content: flex-start;
	   	  justify-content: flex-end; 
	   	  justify-content: center;
	   	  justify-content: space-between;
	   	  justify-content: space-around;
	   }

	   section div{
           width: 200px;
	   }

	   div:nth-child(1) {
	   	  background-color: pink;  
	   }

	   div:nth-child(2) {
	   	  background-color: red;
	   	  margin: 0 6px;
	   }

	   div:nth-child(3) {
	   	  background-color: blue;
	   	  
	   }

	   
	</style>
</head>
<body>
	<section>
		<div>111</div>
		<div>222</div>
		<div>3333</div>
	</section>
</body>
</html>
返回顶层目录

align-items属性详解

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
	   section {
	   	  width: 80%; 
	   	  height: 600px;
	   	  margin: 100px auto;
	   	  border: 1px solid #ccc;
	   	  /*父盒子添加flex*/
	   	  display: flex; /*伸缩布局模式 这个盒子具有弹性*/
	   	  min-width: 500px;
	   	  align-items: stretch; /*默认 子元素高度会拉伸适应父容器(子元素没有设置高度前提下)*/
	   	  align-items: center; /*垂直居中*/
	   	  align-items: flex-start;/*上对齐*/
	   	  align-items: flex-end;/*下对齐*/
	   }

	   section div{
           width: 200px;
           height: 200px;
	   }

	   div:nth-child(1) {
	   	  background-color: pink;  
	   }

	   div:nth-child(2) {
	   	  background-color: red;
	   	  margin: 0 6px;
	   }

	   div:nth-child(3) {
	   	  background-color: blue;
	   	  
	   }

	   
	</style>
</head>
<body>
	<section>
		<div>111</div>
		<div>222</div>
		<div>3333</div>
	</section>
</body>
</html>
返回底层目录

flex-wrap属性

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
	   section {
	   	  width: 80%; 
	   	  height: 600px;
	   	  margin: 100px auto;
	   	  border: 1px solid #ccc;
	   	  /*父盒子添加flex*/
	   	  display: flex; /*伸缩布局模式 这个盒子具有弹性*/
	   	  min-width: 500px;
	   	  flex-wrap: nowrap;
	   	  flex-wrap: wrap-reverse;
	   	  flex-wrap: wrap;
	   	  align-content: space-between;
	   }

	   section div{
           width: 500px;
           height: 200px;
	   }

	   div:nth-child(1) {
	   	  background-color: pink;  
	   }

	   div:nth-child(2) {
	   	  background-color: red;
	   	  margin: 0 6px;
	   }

	   div:nth-child(3) {
	   	  background-color: blue;
	   	  
	   }

	   
	</style>
</head>
<body>
	<section>
		<div>111</div>
		<div>222</div>
		<div>3333</div>
	</section>
</body>
</html>
返回底层目录

返回目录

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值