页面布局练习

一、题目

实现以下图片

二、思路

基于此案例,我们采用最基础的方法实现------浮动。

思路:

1、通过观察图片可以发现,布局整体分为左中右三个部分,所以先设置三个div盒子(L、C、R)用于分别放置这几部分。

2、在L盒子中,可看出分为三部分------上中下,即宽度一致,高度不一致。可通过统一设置宽度,分别设置高度来实现。

3、在C盒子中整体看又可以分为四个中等div盒子,在每个中等div盒子中继续划分。相当于在L盒子的基础上再次进行划分。

4、R盒子和L盒子几乎一致,区别在于R盒子的子盒子更多,并且其中有需要继续划分的盒子。

5、需要注意的是LCR三个盒子的划分虽然不同,但是整体高度一致;并且在C盒子中会发现在CY、CE、CS、CT、CF、CL中在盒子内部上方有边框,需要在样式中进行设置。

三、实现

1、外层盒子的创建

html 复制代码
	<body>

		<div id="L"></div>

		<div id="C"></div>

		<div id="R"></div>
	</body>

2、分别在三个盒子中创建子盒子

(1)L盒子

html 复制代码
        <div id="L">
			<div id="L_1">L_1</div>
			<div id="L_2">L_2</div>
			<div id="L_3">L_3</div>
		</div>

(2)C盒子

html 复制代码
        <div id="C">
			<div id="C_1"></div>

			<div id="C_2"></div>

			<div id="C_3"></div>

			<div id="C_4"></div>
		</div>

(3)R盒子

html 复制代码
		<div id="R">
			<div id="R_1">R_1</div>
			<div id="R_2">R_2</div>
			<div id="R_3">R_3</div>
			<div id="R_4">R_4</div>
			<div id="R_5">R_5</div>
			<div id="R_6">R_6</div>
			<div id="R_7">R_7</div>
		</div>

(4)C盒子的继续划分

html 复制代码
		<div id="C">
			<div id="C_1">
				<div id="C_1_1">C_1_1</div>
				<div id="C_1_2">C_1_2</div>
				<div id="C_1_3">C_1_3</div>
			</div>

			<div id="C_2">
				<div id="CU">CU</div>
				<div id="CYE">
					<div id="CY" >
						<p>CY</p>
					</div>
					<div id="CE">
						<p>CE</p>
					</div>
				</div>
			</div>

			<div id="C_3">
				<div id="CC">CC</div>
				<div id="CST">
					<div id="CS" >
						<p>CS</p>
					</div>
					<div id="CT">
						<p>CT</p>
					</div>
				</div>
			</div>

			<div id="C_4">
				<div id="CD">CD</div>
				<div id="CFL">
					<div id="CF">
						<p>CF</p>
					</div>
					<div id="CL">
						<p>CL</p>
					</div>
				</div>
			</div>
		</div>

3、样式设置

(1)设置盒子浮动

css 复制代码
			div {
				float: left;
			}

(2)宽度设置

设置L、C、R盒子的宽度为300px,设置其子盒子的宽度为300px。

css 复制代码
			#L,
			#C,
			#R {
				width: 300px;
			}

			#L>div,
			#C>div,
			#R>div {
				width: 300px;
			}

(3)设置L盒子子盒子的样式

css 复制代码
			#L_1 {
				height: 80px;
				background-color: lightblue;
			}

			#L_2 {
				height: 300px;
				background-color: greenyellow;
			}

			#L_3 {
				height: 370px;
				background-color: yellow;
			}

(4)设置C盒子的子盒子的样式

  • 设置第二层盒子的高度

    css 复制代码
    			#C_2,
    			#C_3,
    			#C_4 {
    				height: 200px;
    			}
                #CU,
    			#CC,
    			#CD,
    			#CYE,
    			#CST,
    			#CFL {
    				width: 150px;
    			}
  • 设置第三层盒子的宽高

    css 复制代码
    			#C_1_1,
    			#C_1_2,
    			#C_1_3 {
    				width: 100px;
    				height: 150px;
    			}
  • 设置第二层已划分好的盒子的背景色

    css 复制代码
    #C_1_1 {
    				background-color: palevioletred;
    			}
    
    			#C_1_2 {
    				background-color: pink;
    			}
    
    			#C_1_3 {
    				background-color: plum;
    			}
    
    			#CU {
    				height: 200px;
    				background-color: lightcoral;
    			}
    
    			#CC {
    				height: 200px;
    				background-color: deeppink;
    			}
    
    			#CD {
    				height: 200px;
    				background-color: mediumpurple;
    			}
  • 设置第三层盒子的样式及背景色

    css 复制代码
    			#CY,
    			#CE,
    			#CS,
    			#CT,
    			#CF,
    			#CL {
    				border-top: 10px solid #0f9e20;
    				background-color: orange;
    				width: 150px;
    				height: 90px;
    			}

(5)设置R盒子的子盒子的样式

为每个盒子设置高度和背景色

css 复制代码
			#R_1_1,
			#R_1_2 {
				height: 200px;
				width: 150px;
			}

			#R_1_1 {
				background-color: lightblue;
			}

			#R_1_2 {
				background-color: greenyellow;
			}

			#R_2 {
				height: 100px;
				background-color: lightyellow;
			}

			#R_3 {
				height: 100px;
				background-color: coral;
			}

			#R_4 {
				height: 100px;
				background-color: deeppink;
			}

			#R_5 {
				height: 100px;
				background-color: gray;
			}

			#R_6 {
				height: 100px;
				background-color: seagreen;
			}

			#R_7 {
				height: 50px;
				background-color: blue;
			}

四、效果展示

相关推荐
于慨2 天前
Lambda 表达式、方法引用(Method Reference)语法
java·前端·servlet
石小石Orz2 天前
油猴脚本实现生产环境加载本地qiankun子应用
前端·架构
从前慢丶2 天前
前端交互规范(Web 端)
前端
CHU7290352 天前
便捷约玩,沉浸推理:线上剧本杀APP功能版块设计详解
前端·小程序
GISer_Jing2 天前
Page-agent MCP结构
前端·人工智能
王霸天2 天前
💥别再抄网上的Scale缩放代码了!50行源码教你写一个永不翻车的大屏适配
前端·vue.js·数据可视化
小领航2 天前
用 Three.js + Vue 3 打造炫酷的 3D 行政地图可视化组件
前端·github
@大迁世界2 天前
2026年React大洗牌:React Hooks 将迎来重大升级
前端·javascript·react.js·前端框架·ecmascript
PieroPc2 天前
一个功能强大的 Web 端标签设计和打印工具,支持服务器端直接打印到局域网打印机。Fastapi + html
前端·html·fastapi
悟空瞎说2 天前
深入 Vue3 响应式:为什么有的要加.value,有的不用?从设计到源码彻底讲透
前端·vue.js