使用弹性盒子flex对html进行布局和动态计算视口高度

使用弹性盒子flex对html进行布局的一个练习

height: calc(100vh - 4px);   # vh表示视口高度的百分比,所以100vh表示整个视口的高度。

.mytxt {

    text-indent: 2em; /* 首航缩进2字符 */

    line-height: 2; /* 2倍行高 */

    padding: 8px; /* 内容与边框的距离 */

}

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<script src="jquery.min.js"></script>
		<style>
			body {
				margin: 0;
				padding: 0;
			}
			/* 在css中设置 row */
			.content{
				width: 100%;
				#height: 700px;
			    height: calc(100vh - 4px);
				
				display : flex; /* 弹性盒子布局 */
				flex-direction: row;   /* flex-direction属性决定主轴的方向 */
				/*  justify-content属性定义了项目在主轴上的对齐方式 */
				justify-content: flex-start;
				align-content:flex-start; /*  align-items属性定义项目在交叉轴(侧轴)上如何对齐  */
				
			}
			.content-item{		
				border:1px solid red;
				margin: 10px;
			}
			.item1{
				width:45%;
			
			}
			.item2{
				width:55%;	
			}
			
			.leftrow1 {
			border:1px solid blue;
				width:100%;
				height:30%;
			}
			.leftrow2 {
				border:1px solid blue;
				width:100%;
				height:30%;
			}
			.leftrow3 {
				border:1px solid blue;
				width:100%;
				height:40%;
			}
			
			
			.rightrow {
				border:1px solid green;
				width:100%;
				height:50%;
			}


			.mytxt {				
				text-indent: 2em; /* 首航缩进2字符 */
				line-height: 2; /* 2倍行高 */
				padding: 8px; /* 内容与边框的距离 */
			}
		</style>
	</head>
	<body>
		<div class="content" id="app">
			<!-- left 45% -->
			<div class="content-item item1">
				<div class="leftrow1"></div>
				<div class="leftrow2"></div>
				<div class="leftrow3  content">
					<div class="content-item item1"></div>		
					<div class="content-item item2"></div>		
				</div>			
			</div>
			<!-- left 55% -->
			<div class="content-item item2">
				<div class="rightrow"></div>
				<div class="rightrow content">
					<div class="content-item item1"></div>		
					<div class="content-item item2"></div>		
				</div>
			
			</div>		
		</div>
		
	</body>
	
</html>



效果如图

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值