css3 flex 布局——骰子

flex 布局小demo——骰子练习

  • 单项目
  • 两个项目
  • 三个项目
  • 四个项目
  • 九个项目

单项目

(1)

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>flex 布局——骰子</title>
	<style type="text/css">
		*{
			padding:0;
			margin:0;
		}
		body {
			display: flex;
			display: -webkit-flex; /* Safari */
		}
		ul,li {
			margin: 0;
			padding: 0;
			list-style: none; 
		}
		.container {
			display: flex;
			display: -webkit-flex; /* Safari */
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}

		.container li {
			height: 30px;
			width: 30px;
			background: #fff;
			border-radius: 50px;
		}
	</style>
</head>
<body>
	<ul class="container">
		<li></li>
	</ul>
</body>
</html>

css3 flex 布局——骰子_第1张图片
(2)

		.container {
			display: flex;
			justify-content: center;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}

css3 flex 布局——骰子_第2张图片
(3)

		.container {
			display: flex;
			justify-content: flex-end;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}

css3 flex 布局——骰子_第3张图片
(4)

		.container {
			display: flex;
			align-items: center;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}

css3 flex 布局——骰子_第4张图片
(5)

		.container {
			display: flex;
			justify-content: center;
			align-items: center;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}

css3 flex 布局——骰子_第5张图片

(6)

		.container {
			display: flex;
			justify-content: flex-end;
			align-items: center;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}

css3 flex 布局——骰子_第6张图片
(7)

		.container {
			display: flex;
			align-items: flex-end;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}

css3 flex 布局——骰子_第7张图片
(8)

		.container {
			display: flex;
			justify-content: center;
			align-items: flex-end;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}

css3 flex 布局——骰子_第8张图片
(9)

		.container {
			display: flex;
			justify-content: flex-end;
			align-items: flex-end;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}

css3 flex 布局——骰子_第9张图片

两个项目

(1)

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>flex 布局——骰子</title>
	<style type="text/css">
		*{
			padding:0;
			margin:0;
		}
		body {
			display: flex;
			display: -webkit-flex; /* Safari */
		}
		ul,li {
			margin: 0;
			padding: 0;
			list-style: none; 
		}
		.container {
			display: flex;
			display: -webkit-flex; /* Safari */
			justify-content: space-between;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}
		.container li {
			height: 30px;
			width: 30px;
			background: #fff;
			border-radius: 50px;
		}
	</style>
</head>
<body>
	<ul class="container">
		<li class="item"></li>
		<li class="item"></li>
	</ul>
</body>
</html>

css3 flex 布局——骰子_第10张图片
(2)

		.container {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}

css3 flex 布局——骰子_第11张图片
(3)

		.container {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			align-items: center;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}

css3 flex 布局——骰子_第12张图片
(4)

		.container {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			align-items: flex-end;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}

css3 flex 布局——骰子_第13张图片
(5)

		.container {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: flex-end;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}

css3 flex 布局——骰子_第14张图片
(6)

		.container {
			display: flex;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}

css3 flex 布局——骰子_第15张图片
(7)

		.container {
			display: flex;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}
		.item:nth-child(2) {
			align-self: center;
		}

如果不设置align-self: center,即为上面(7)的图案。
让第二个item元素垂直居中,即得到下图:
css3 flex 布局——骰子_第16张图片
(8)

		.container {
			display: flex;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}
		.item:nth-child(2) {
			align-self: flex-end;
		}

css3 flex 布局——骰子_第17张图片
(9)

		.container {
			display: flex;
			justify-content: space-between;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}
		.item:nth-child(2) {
			align-self: center;
		}

css3 flex 布局——骰子_第18张图片
(10)

		.container {
			display: flex;
			justify-content: space-between;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}
		.item:nth-child(2) {
			align-self: flex-end;
		}

css3 flex 布局——骰子_第19张图片

三个项目

(1)

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>flex 布局——骰子</title>
	<style type="text/css">
		*{
			padding:0;
			margin:0;
		}
		body {display: flex;}
		ul,li {
			margin: 0;
			padding: 0;
			list-style: none; 
		}
		.container {
			display: flex;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}
		.container li {
			height: 30px;
			width: 30px;
			background: #fff;
			border-radius: 50px;
		}
	</style>
</head>
<body>
	<ul class="container">
		<li class="item"></li>
		<li class="item"></li>
		<li class="item"></li>
	</ul>
</body>
</html>

css3 flex 布局——骰子_第20张图片
(2)

		.container {
			display: flex;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}
		.item:nth-child(2) {
			align-self: center;
		}
		.item:nth-child(3) {
			align-self: flex-end;
		}

css3 flex 布局——骰子_第21张图片

四个项目

(1)

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>flex 布局——骰子</title>
	<style type="text/css">
		*{
			padding:0;
			margin:0;
		}
		body {display: flex;}
		ul,li {
			margin: 0;
			padding: 0;
			list-style: none; 
		}
		.container {
			display: flex;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}
		.container li {
			height: 30px;
			width: 30px;
			background: #fff;
			border-radius: 50px;
		}
	</style>
</head>
<body>
	<ul class="container">
		<div class="column">
			<li class="item"></li>
			<li class="item"></li>
		</div>
		<div class="column">
			<li class="item"></li>
			<li class="item"></li>
		</div>
	</ul>
</body>
</html>

css3 flex 布局——骰子_第22张图片
(2)

		.container {
			display: flex;
			flex-wrap: wrap;
			align-content: space-between;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}
		.column{
			display: flex;
			justify-content: space-between;
		}

css3 flex 布局——骰子_第23张图片
(3)

		.container {
			display: flex;
			flex-wrap: wrap;
			align-content: space-between;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}
		.column{
			flex-basis: 100%;
			display: flex;
			justify-content: space-between;
		}

css3 flex 布局——骰子_第24张图片

九个项目

(1)

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>flex 布局——骰子</title>
	<style type="text/css">
		*{
			padding:0;
			margin:0;
		}
		body {display: flex;}
		ul,li {
			margin: 0;
			padding: 0;
			list-style: none; 
		}
		.container {
			display: flex;
			flex-wrap: wrap;
			width: 100px;
			height: 100px;
			margin: 100px;
			background: #333;
			border-radius: 10px;
		}
		.container li {
			height: 30px;
			width: 30px;
			background: #fff;
			border-radius: 50px;
		}
	</style>
</head>
<body>
	<ul class="container">
		<li class="item"></li>
		<li class="item"></li>
		<li class="item"></li>
		<li class="item"></li>
		<li class="item"></li>
		<li class="item"></li>
		<li class="item"></li>
		<li class="item"></li>
		<li class="item"></li>
	</ul>
</body>
</html>

css3 flex 布局——骰子_第25张图片

你可能感兴趣的:(前端)