CSS属性其他小案例

CSS小案例

  • 运动的汽车

  • 无缝滚动

  • 传统三等分

  • 伸缩布局实现三等分

  • 伸缩布局实现固定高度

  • 伸缩布局实现排列方式

  • justify-content属性


运动的汽车


<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Documenttitle>
	<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>

返回顶层目录


无缝滚动


<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Documenttitle>
	<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>

返回顶层目录


传统三等分


<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Documenttitle>
	<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>

返回顶层目录


伸缩布局实现三等分


<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Documenttitle>
	<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>

返回顶层目录


伸缩布局实现固定高度


<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Documenttitle>
	<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>111div>
		<div>222div>
		<div>3333div>
		<div>4444div>
	section>
body>
html>

返回顶层目录


伸缩布局实现排列方式


<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Documenttitle>
	<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>111div>
		<div>222div>
		<div>3333div>
		<div>4444div>
	section>
body>
html>

返回顶层目录


justify-content属性


<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Documenttitle>
	<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>111div>
		<div>222div>
		<div>3333div>
	section>
body>
html>

返回顶层目录


align-items属性详解


<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Documenttitle>
	<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>111div>
		<div>222div>
		<div>3333div>
	section>
body>
html>

返回底层目录


flex-wrap属性


<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Documenttitle>
	<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>111div>
		<div>222div>
		<div>3333div>
	section>
body>
html>

返回底层目录


返回目录

你可能感兴趣的:(前端,CSS属性其他小案例)