使用flex布局写出色子案例

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

flex布局是一个应用非常广泛的布局,再网页的制作中非常好用,今天我们就通过这个骰子的案例学习一下,下面是代码成果展示:


一、Flex是什么?

Flex 是 Flexible Box 的缩写,意为“弹性布局”或者“弹性盒子”,是 CSS3 中的一种新的布局模式,可以简便、完整、响应式地实现各种页面布局,当页面需要适应不同的屏幕大小以及设备类型时非常适用。目前,几乎所有的浏览器都支持 Flex 布局

二、代码内容

1.html

代码如下(示例):

<body>
		<div class="boby">
			<div id="con">
			<div class="num1">
				<div></div>
				
			</div>	
			</div>
			
			<div id="con">
				<div class="num2">
				<div></div>
				<div></div>
			</div>
			</div>
			
			<div id="con">
				<div class="num3">
				<div></div>
				<div></div>
				<div></div>
				
			</div>
			</div>
			
			
			<div id="con">
					<div class="num4">
				<div class="coulum">
					<div></div>
					<div></div>
				</div>
				<div class="coulum">
					<div></div>
					<div></div>
				</div>
			</div>
			</div>
			
			<div id="con">
				<div class="num5">
					<div class="coulum">
						<div></div>
						<div></div>
					</div>
					<div class="coulum">
						<div></div>
					</div>
					<div class="coulum">
						<div></div>
						<div></div>
					</div>
				
			</div>
			</div>
			
			<div id="con">
				<div class="num6">
					<div class="coulum">
						<div></div>
						<div></div>
					</div>
					<div class="coulum">
						<div></div>
						<div></div>
					</div>
					<div class="coulum">
						<div></div>
						<div></div>
					</div>
				
			</div>
			</div>
			
			
			
		</div>
	</body>

2.css

代码如下(示例):

			.boby{
			
			display: flex;
			width: 1000px;
			height: 1000px;
			
			background-color: lightgray;
			flex-wrap: wrap;
			
			
		}
		.boby #con{
			display: flex;
			justify-content: center;
			align-items: center;
			
			width:33.3%;
			height: 50%;
		}
		.boby .num1 {
			display: flex;
			border: 0px solid gainsboro ;
			width: 200px;
			height: 200px;
			background-color: white;
			border-radius: 20px;
			box-shadow: 5px 15px 25px gray ;
			justify-content: center;
			align-items: center;
		}
		.boby .num1 div{
			
			width: 40px;
			height: 40px;
			background-color: red;
			
			border-radius: 150px;
		}
		.boby .num2 {
		
		
			display: flex;
			border: 0px solid gainsboro ;
			width: 200px;
			height: 200px;
			background-color: white;
			border-radius: 20px;
			box-shadow: 5px 15px 25px gray ;
			flex-direction: column;
			
			justify-content: space-around;
			
		}
		.boby .num2 div{
			
			margin: 30px;
			
			width: 40px;
			height: 40px;
			background-color: red;
			
			border-radius: 150px;
		}
		.boby .num2 div:nth-child(2){
			align-self: flex-end;
		}
		
		.boby .num3 {
		
		
			display: flex;
			border: 0px solid gainsboro ;
			width: 200px;
			height: 200px;
			background-color: white;
			border-radius: 20px;
			box-shadow: 5px 15px 25px gray ;
			flex-direction: column;
			
			justify-content: space-around;
			
		}
		.boby .num3 div{
			
			margin: 10px;
			
			width: 40px;
			height: 40px;
			background-color: red;
			
			border-radius: 150px;
		}
		.boby .num3 div:nth-child(2){
			align-self: center;
		}
		
		.boby .num3 div:nth-child(3){
			align-self: flex-end;
		}
		.boby .num4{
			display: flex;
			border: 0px solid gainsboro ;
			width: 200px;
			height: 200px;
			background-color: white;
			border-radius: 20px;
			box-shadow: 5px 15px 25px gray ;
			flex-direction: column;
			
			justify-content: space-around;
		}
		
		.boby .num4 .coulum{
			display: flex;
			flex-direction: row;
			justify-content: space-around;
		}
		
		.boby .num4 .coulum div{
			width: 40px;
			height: 40px;
			background-color: red;
			
			border-radius: 150px;
			
		}
		.boby .num5{
			
			display: flex;
			border: 0px solid gainsboro ;
			width: 200px;
			height: 200px;
			background-color: white;
			border-radius: 20px;
			box-shadow: 5px 15px 25px gray ;
			flex-direction: column;
			
			justify-content: space-around;
		}
		
		.boby .num5 .coulum{
			
			display: flex;
			flex-direction: row;
			justify-content: space-around;
		}
		.boby .num5 .coulum div{
			width: 40px;
			height: 40px;
			background-color: red;
			
			border-radius: 150px;
			
		}
		
		.boby .num6{
			
			display: flex;
			border: 0px solid gainsboro ;
			width: 200px;
			height: 200px;
			background-color: white;
			border-radius: 20px;
			box-shadow: 5px 15px 25px gray ;
			flex-direction: column;
			
			justify-content: space-around;
		}
		
		.boby .num6 .coulum{
			
			display: flex;
			flex-direction: row;
			justify-content: space-around;
		}
		.boby .num6 .coulum div{
			width: 40px;
			height: 40px;
			background-color: red;
			
			border-radius: 150px;
			
		}
	</style>

该处使用的url网络请求的数据。


总结

好了,今天的flex骰子布局分享就到这里了!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值