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

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

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

.mytxt {

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

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

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

}

html 复制代码
<!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>

效果如图

相关推荐
hashiqimiya38 分钟前
两个步骤,打包war,tomcat使用war包
java·服务器·前端
零度@1 小时前
Java中Map的多种用法
java·前端·python
yuanyxh2 小时前
静默打印程序实现
前端·react.js·electron
三十_A3 小时前
如何正确实现圆角渐变边框?为什么 border-radius 对 border-image 不生效?
前端·css·css3
小满zs3 小时前
Next.js第十三章(缓存组件)
前端
jumu2023 小时前
3 次 B 样条优化:为你的 Matlab 程序加速
css
前端老宋Running3 小时前
“受控组件”的诅咒:为什么你需要 React Hook Form + Zod 来拯救你的键盘?
前端·javascript·react.js
风止何安啊3 小时前
拿捏 React 组件通讯:从父子到跨组件的「传功秘籍」
前端·react.js·面试
懒得不想起名字3 小时前
将flutter打成aar包嵌入到安卓
前端
Highcharts.js4 小时前
官方文档|Angular 框架集成 Highcharts Dashboards
前端·javascript·angular.js·highcharts·看板·使用文档·dashboards