<学习记录>Flex实现的几种布局

本文通过三个实例展示了HTML和CSS在页面布局方面的应用:一是创建骰子布局,利用CSS实现不同形状和排列的骰子;二是实现流式布局,展示了如何用flexbox进行响应式内容排列;三是设计输入框布局,包括添加按钮、搜索框和提交按钮的对齐方式。这些实例有助于理解HTML和CSS在网页布局中的灵活性和实用性。
摘要由CSDN通过智能技术生成

一、骰子布局
效果图
实现代码:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
	
		.box{
			position:relative;
			width:1000px;
			height:1000px;
			/*flex*/
			display:flex;
			justify-content:space-around;
			align-items:center;
			}
		section
		{
			box-sizing:border-box;
			border-radius:10px;
			background-color:#ddd;
			width:80px;
			height:80px;
			/*flex*/
			display:flex;
		}
		.stone{
			width:20px;
			height:20px;
			border-radius:50%;
			background-color:#000;		
		}
		
		.box >:first-child
		{
			justify-content:center;
			align-items:center;
		}
		.box >:nth-child(2)
		{
			padding:5px;
			justify-content:space-between;
			
		}
			.box >:nth-child(2) >:nth-child(2)
			{
					align-self:flex-end;
			}
		.box >:nth-child(3)
		{
			padding:5px;
			justify-content:space-around;
		}
			.box >:nth-child(3) >:nth-child(2)
			{
				align-self:center;
			}
			.box >:nth-child(3) >:nth-child(3)
			{
				align-self:flex-end;
			}
		.box >:nth-child(4)
		{
			padding:5px;
			justify-content:space-between;
			flex-direction:column;
		}
			.box >:nth-child(4) div
			{
				display:flex;
				justify-content:space-between;
			}
		.box >:nth-child(5)
		{
			padding:5px;
			justify-content:space-around;
		}
			.box >:nth-child(5) > div
			{
				display:flex;
				flex-direction:column;
				justify-content:space-between;
			}
			.box >:nth-child(5) >:nth-child(2)
			{
				align-self:center;
			}
		.box >:last-child
		{
			padding:5px 6px;
			justify-content:space-between;
		}
			.box >:last-child >div
			{
				display:flex;
				flex-direction:column;
				justify-content:space-around;
			}
			
		</style>
	</head>
	<body>
		<div class="box">
			<section>
				<div class="stone"></div>
			</section>
			<section>
				<div class="stone"></div>
				<div class="stone"></div>
			</section>
			<section>
				<div class="stone"></div>
				<div class="stone"></div>
				<div class="stone"></div>
			</section>
			<section>
				<div>
					<div class="stone"></div>
					<div class="stone"></div>
				</div>
				<div>
					<div class="stone"></div>
					<div class="stone"></div>
				</div>
			</section>
			<section>
				<div>
					<div class="stone"></div>
					<div class="stone"></div>
				</div>
				<div class="stone"></div>
				<div>
					<div class="stone"></div>
					<div class="stone"></div>
				</div>
			</section>
			<section>
				<div>
					<div class="stone"></div>
					<div class="stone"></div>
					<div class="stone"></div>
				</div>
				<div>
					<div class="stone"></div>
					<div class="stone"></div>
					<div class="stone"></div>
				</div>
			</section>
		</div>
	</body>
</html>

二、流式布局
效果图
代码:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
		*{
			padding: 0;
			margin: 0;
			box-sizing: border-box;
		}
		.wrap{
			width:300px;
			height:600px;
			border:1px solid #000;
			display: flex;
			flex-wrap: wrap;
			align-content: flex-start;
		}
		.wrap>div{
			width:25%;
			height:100px;
			border:1px solid red;
			background: thistle;
			text-align: center;
			line-height: 100px;
			font-size: 50px;
			
		}
		</style>
	</head>
	<body>
		<div class="wrap">
			<div>1</div>
			<div>2</div>
			<div>3</div>
			<div>4</div>
			<div>5</div>
			<div>6</div>
			<div>7</div>
			<div>8</div>
			<div>9</div>
			<div>10</div>
			<div>11</div>
			<div>12</div>
		</div>
	</body>
</html>

三、输入框布局
效果图

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
		*{
			margin: 0;
			padding: 0;
			box-sizing: border-box;
		}
		.header{
			height: 60px;
			display: flex;
		}
		.add{
			background-color: #D8BFD8;
			text-align: center;
			line-height: 60px;
			color: #fff;
			width: 60px;
		}
		.sub{
			width: 100px;
		}
		.search{
			flex-grow: 1;
		}
		</style>
	</head>
	<body>
		<div class="header">
			<div class="add">地址</div>
			<input type="text" class="search" />
			<input type="button"  value="提交" class="sub" />
		</div>
		</header>
	</body>
</html>

在这里插入图片描述

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
		*{
			margin:0;
			padding:0;
			box-sizing: border-box;
		}
	
		.wrap{
			display: flex;
		}
		.para{
			flex-grow: 1;
			background: #DDDDDD;
			font-size: 20px;
			font-family: 宋体;
		}
		</style>
	</head>
	<body>
		<div class="wrap">
			<div class="left" >
				<div class="box"></div>
				<img src="img/皮卡丘.jpg" width="50" height="50"/>
			</div>
			<div class="para">皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡皮卡皮皮卡丘皮卡皮卡
			</div>
	</div>
	</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值