HTML+CSS 实战应用

简介

本部分通过一个实际的网页制作,来综合html与css语法的使用,从实际开发的过程中掌握页面布局的排版方式。

效果图总览

1.标题与首页图

Java前端开发系统案例 前端开发案例教程_Vue

2.精品课程推荐

Java前端开发系统案例 前端开发案例教程_Java前端开发系统案例_02

3.前端开发显示

Java前端开发系统案例 前端开发案例教程_Java前端开发系统案例_03

4.网页脚标

Java前端开发系统案例 前端开发案例教程_css_04

开发阶段代码

1.基础样式

/* 基础公共样式:清除默认样式 + 设置通用样式 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

li {
  list-style: none;
}

/* 所有内容的文字 */
body {
  font: 14px/1.5 "Microsoft Yahei", "Hiragino Sans GB", "Heiti SC", "WenQuanYi Micro Hei", sans-serif;
  color: #333;
}

/* 所有超链接的文字颜色 */
a {
  color: #333;
  text-decoration: none;
}

2.首页html代码

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>学成在线首页</title>
		<!-- 需要引入自己定义的css样式 -->
		<!-- 1.首先引入基础样式,清除原有的盒子模型,列表等 -->
		<link rel="stylesheet" href="./css/base.css" />
		<link rel="stylesheet" href="./css/index.css" />
	</head>
	<body>
		<!-- 先整体在局部,从上到下,从左到右 -->
		<!-- 头部区域:一共分为四部分 -->
		<div class="header">
			<div class="wrapper">
				<!-- logo -->
				<!-- 制作方式:h1>a>标题名称 -->
				<div class="logo">
					<h1>
						<a href="#">学成在线</a>
					</h1>
				</div>
				<!-- 导航 -->
				<!-- 制作方式 ul>li>a -->
				<div class="nav">
					<ul>
						<li><a href="#" class="active">首页</a></li>
						<li><a href="#">课程</a></li>
						<li><a href="#">职业规划</a></li>
					</ul>
				</div>
				<!-- 搜索框 -->
				<!-- input标签+a标签(搜索图标) -->
				<div class="search">
					<input type="text" placeholder="请输入关键词" />
					<!-- 此处显示背景搜索图标 -->
					<a href="#"></a>
				</div>
				<!-- 用户中心 -->
				<!-- 用户头像+用户名:a>img+span -->
				<div class="user">
					<a href="#">
						<img src="./uploads/user.png" />
						<span>MrZhang</span>
					</a>
				</div>
			</div>
		</div>
		
		<!-- banner区域 -->
		<div class="banner">
			<!-- 版心区域 -->
			<div class="wrapper">
				<!-- 左边菜单栏 -->
				<div class="left">
					<ul>
						<li><a href="#">前端开发</a></li>
						<li><a href="#">后端开发</a></li>
						<li><a href="#">移动开发</a></li>
						<li><a href="#">人工智能</a></li>
						<li><a href="#">商业预测</a></li>
						<li><a href="#">云计算&大数据</a></li>
						<li><a href="#">运维&测试</a></li>
						<li><a href="#">UI设计</a></li>
						<li><a href="#">产品</a></li>
					</ul>
				</div>
				<!-- 右边课程表 -->
				<div class="right">
					<h3>我的课程表</h3>
					<div class="content">
						<!-- 使用dl dt dd这种标签,描述标题和内容的 -->
						<dl>
							<dt>数据可视化课程</dt>
							<dd><span>正在学习</span>-<strong>echarts使用步骤</strong></dd>
						</dl>
						<dl>
							<dt>Vue3医疗项目课程</dt>
							<dd><span>正在学习</span>-<strong>认识组合式API</strong></dd>
						</dl>
						<dl>
							<dt>React核心技术课程</dt>
							<dd><span>正在学习</span>-<strong>rudex配合TS使用</strong></dd>
						</dl>
						<a href="#">全部课程</a>
					</div>
				</div>
			</div>
		</div>
		
		<!-- 精品推荐区域 -->
		<div class="recommend wrapper">
			<h3>精品推荐</h3>
			<ul>
				<li><a href="#">HTML</a></li>
				<li><a href="#">CSS</a></li>
				<li><a href="#">JavaScript</a></li>
				<li><a href="#">Node.js</a></li>
				<li><a href="#">Ajax</a></li>
				<li><a href="#">Vue2.0</a></li>
				<li><a href="#">Vue3.0</a></li>
				<li><a href="#">TypeScript</a></li>
				<li><a href="#">React</a></li>
			</ul>
			<a href="#" class="modify">修改兴趣</a>
		</div>
		
		<!-- 精品推荐课程-卡片显示区域 -->
		<div class="course wrapper">
			<!-- 本区域:一个是标题hd,一个是内容bd -->
			<div class="hd">
				<h3>精品推荐</h3>
				<a href="#" class="more">查看全部</a>
			</div>
			
			<div class="bd">
				<ul>
					<li>
						<!-- 每一个卡成区域都有图片、文字(标题、状态文字) -->
						<div class="pic"><img src="uploads/course01.png"></div>
						<div class="text">
							<h4>JavaScript数据看板项目实战</h4>
							<p><span>高级</span> · <i>11254</i>人在学习</p>
						</div>
					</li>
					
					<li>
					  <a href="#">
					    <div class="pic"><img src="./uploads/course02.png" alt=""></div>
					    <div class="text">
					      <h4>Vue.js实战——面经全端项目</h4>
					      <p><span>高级</span> · <i>2726</i>人在学习</p>
					    </div>
					  </a>
					</li>
					<li>
					  <a href="#">
					    <div class="pic"><img src="./uploads/course03.png" alt=""></div>
					    <div class="text">
					      <h4>玩转Vue全家桶,iHRM人力资源项目</h4>
					      <p><span>高级</span> · <i>9456</i>人在学习</p>
					    </div>
					  </a>
					</li>
					<li>
					  <a href="#">
					    <div class="pic"><img src="./uploads/course04.png" alt=""></div>
					    <div class="text">
					      <h4>Vue.js实战医疗项目——优医问诊</h4>
					      <p><span>高级</span> · <i>7192</i>人在学习</p>
					    </div>
					  </a>
					</li>
					<li>
					  <a href="#">
					    <div class="pic"><img src="./uploads/course05.png" alt=""></div>
					    <div class="text">
					      <h4>小程序实战:小兔鲜电商小程序项目</h4>
					      <p><span>高级</span> · <i>2703</i>人在学习</p>
					    </div>
					  </a>
					</li>
					<li>
					  <a href="#">
					    <div class="pic"><img src="./uploads/course06.png" alt=""></div>
					    <div class="text">
					      <h4>前端框架Flutter开发实战</h4>
					      <p><span>高级</span> · <i>2841</i>人在学习</p>
					    </div>
					  </a>
					</li>
					<li>
					  <a href="#">
					    <div class="pic"><img src="./uploads/course07.png" alt=""></div>
					    <div class="text">
					      <h4>熟练使用React.js——极客园H5项目</h4>
					      <p><span>高级</span> · <i>95682</i>人在学习</p>
					    </div>
					  </a>
					</li>
					<li>
					  <a href="#">
					    <div class="pic"><img src="./uploads/course08.png" alt=""></div>
					    <div class="text">
					      <h4>熟练使用React.js——极客园PC端项目</h4>
					      <p><span>高级</span> · <i>904</i>人在学习</p>
					    </div>
					  </a>
					</li>
					<li>
					  <a href="#">
					    <div class="pic"><img src="./uploads/course09.png" alt=""></div>
					    <div class="text">
					      <h4>前端实用技术,Fetch API 实战</h4>
					      <p><span>高级</span> · <i>1516</i>人在学习</p>
					    </div>
					  </a>
					</li>
					<li>
					  <a href="#">
					    <div class="pic"><img src="./uploads/course10.png" alt=""></div>
					    <div class="text">
					      <h4>前端高级Node.js零基础入门教程</h4>
					      <p><span>高级</span> · <i>2766</i>人在学习</p>
					    </div>
					  </a>
					</li>
				</ul>
			</div>
		</div>
		
		<!-- 前端开发工程师 -->
		<div class="wrapper">
			<!-- 标题区域 -->
			<div class="hd">
				<h3>前端开发工程师</h3>
				
				<ul>
					<li><a href="#" class="active">热门</a></li>
					<li><a href="#">初级</a></li>
					<li><a href="#">中级</a></li>
					<li><a href="#">高级</a></li>
				</ul>
				<a href="#" class="more">查看全部</a>
			</div>
			<!-- 内容区域 -->
			<div class="bd">
				<!-- 左边一张图片 -->
				<div class="left">
					<img src="./uploads/web_left.png" />
				</div>
				
				<div class="right">
					<!-- 右边分为顶部图片与底部图片 -->
					<div class="top"><img src="uploads/web_top.png" /></div>
					<div class="bottom">
						<ul>
						  <li>
						    <a href="#">
						      <div class="pic"><img src="./uploads/web01.png" alt=""></div>
						      <div class="text">
						        <h4>JS高级javaScript进阶面向对象ES6</h4>
						        <p><span>高级</span> · <i>101937</i>人在学习</p>
						      </div>
						    </a>
						  </li>
						  <li>
						    <a href="#">
						      <div class="pic"><img src="./uploads/web02.png" alt=""></div>
						      <div class="text">
						        <h4>零基础玩转微信小程序</h4>
						        <p><span>高级</span> · <i>133781</i>人在学习</p>
						      </div>
						    </a>
						  </li>
						  <li>
						    <a href="#">
						      <div class="pic"><img src="./uploads/web03.png" alt=""></div>
						      <div class="text">
						        <h4>JavaScript基础——语法解析+项目实战</h4>
						        <p><span>高级</span> · <i>8927</i>人在学习</p>
						      </div>
						    </a>
						  </li>
						  <li>
						    <a href="#">
						      <div class="pic"><img src="./uploads/web04.png" alt=""></div>
						      <div class="text">
						        <h4>前端框架Vue2+Vue3全套视频</h4>
						        <p><span>高级</span> · <i>26022</i>人在学习</p>
						      </div>
						    </a>
						  </li>
						</ul>
					</div>
				</div>
			</div>
		</div>
		
		<!-- 版权信息 -->
		<div class="footer">
			<div class="wrapper">
				<div class="left">
					<!-- 一张图片,一段版权描述,一个连接按钮 -->
					<a href="#"><img src="images/logo.png"/></a>
					<p>
						学成在线致力于普及中国最好的教育它与中国一流大学和机构合作提供在线课程。
						© 2017年XTCG Inc.保留所有权利。-沪ICP备15025210号
					</p>
					<a href="#" class="download">下载APP</a>
				</div>
				<div class="right">
					<dl>
					    <dt>关于学成网</dt>
					    <dd><a href="#">关于</a></dd>
					    <dd><a href="#">管理团队</a></dd>
					    <dd><a href="#">工作机会</a></dd>
					    <dd><a href="#">客户服务</a></dd>
					    <dd><a href="#">帮助</a></dd>
					</dl>
					<dl>
					    <dt>新手指南</dt>
					    <dd><a href="#">如何注册</a></dd>
					    <dd><a href="#">如何选课</a></dd>
					    <dd><a href="#">如何拿到毕业证</a></dd>
					    <dd><a href="#">学分是什么</a></dd>
					    <dd><a href="#">考试未通过怎么办</a></dd>
					</dl>
					<dl>
					    <dt>合作伙伴</dt>
					    <dd><a href="#">合作机构</a></dd>
					    <dd><a href="#">合作导师</a></dd>
					</dl>
				</div>
			</div>
		</div>
		
	</body>
</html>

3.首页相关样式

/* 首页样式 */
/* 版心居中 */
.wrapper{
	margin: 0 auto;
	width: 1200px;
}
/* body的背景颜色 */
body{
	/* 浅灰色 */
	background-color: #f3f5f7;
}

/* 头部区域的样式 */
.header{
	height: 100px;
	background-color: #fff;
}

.header .wrapper{
	padding-top: 29px;
	display: flex;
}

/* 分别对导航中的其他模块进行修饰排版 */
/* logo */
.logo a{
	/* 需要添加block属性,图片才能显示完全 */
	display: block;
	width: 195px;
	height: 41px;
	background-image: url(../images/logo.png);
	/* 为了隐藏标题,将字体设置为0 */
	font-size: 0;
}

/* 导航栏 */
.nav{
	margin-left: 102px;
}

.nav ul{
	display: flex;
}

.nav li{
	margin-right: 24px;
}

.nav li a{
	display: block;
	/* 内边距,上下6 左右8 */
	padding: 6px 8px;
	line-height: 27px;
	font-size: 19px;
}

/* active 类选择器,用于标识选中 */
.nav li .active,
.nav li a:hover{
	border-bottom: 2px solid #00a4ff;
}

/* 搜索区域 */
.search{
	display: flex;
	margin-left: 64px;
	padding-left: 19px;
	padding-right: 12px;
	width: 412px;
	height: 40px;
	background-color: #f3f5f7;
	border-radius: 20px;
}

.search input{
	/* 充满整个搜索区域 */
	flex: 1;
	/* 去除边框、背景色设置为空白、去除点击输入的边框 */
	border: 0;
	background-color: transparent;
	outline: none;
}

/* 搜索的文字样式 */
.search input::placeholder{
	font-size: 14px;
	color: #999;
}
/* 搜索的图标 */

/* 父级元素已经进行了flex布局,子级元素变为弹性盒子:加宽度高度是自动生效的 */
.search a{
	/* 侧向居中,就是纵向居中 */
	align-self: center;
	width: 16px;
	height: 16px;
	background-image: url(../images/search.png);
}

/* 用户 */
.user{
	margin-left: 32px;
	margin-top: 4px;
}
.user img{
	margin-right: 7px;
	/* vertical-align 行内块和行内垂直方向对齐方式 */
	/* 将行内的文字垂直居中 */
	vertical-align: middle;
}

.user span{
	font-size: 16px;
	color: #666;
}

/* 此处为banner区域的样式 */
.banner{
	height: 420px;
	background-color: #0092cb;
}

.banner .wrapper{
	/* 版心区域 */
	display: flex;
	justify-content: space-between;
	height: 420px;
	background-image: url(../uploads/banner.png);
}

/* 侧导航 */
.banner .left{
	/* 设置内边距 */
	/* 上下为3px,左右为20px */
	padding: 3px 20px;
	width: 191px;
	height: 420px;
	background-color: rgba(0,0,0,0.42);
}

.banner .left a{
	/* 块级元素:宽度是父级的100% */
	display: block;
	height: 46px;
	background: url(../images/right.png) no-repeat right center;
	line-height: 46px;
	font-size: 16px;
	color: #fff;
}

.banner .left a:hover{
	/* 鼠标悬停 */
	background-image: url(../images/right-hover.png);
	color: #00a4ff;
}

/* 右边的课程表 */
.banner .right{
	margin-top: 60px;
	height: 305px;
	width: 218px;
	background-color: #209dd5;
	border-radius: 10px;
}

.banner .right h3{
	margin-left: 14px;
	height: 48px;
	line-height: 48px;
	font-size: 15px;
	color: #fff;
	font-weight: 400;
}

.banner .right .content{
	padding: 14px;
	height: 257px;
	background-color: #fff;
	border-radius: 10px;
}

.banner .right dl{
	margin-bottom: 12px;
	border-bottom: 1px solid #e0e0e0;
} 

.banner .right dt{
	margin-bottom: 8px;
	font-size: 14px;
	line-height: 20px;
	font-weight: 700;
}

.banner .right dd{
	margin-bottom: 8px;
	font-size: 12px;
	line-height: 16px;
}

.banner .right dd span{
	color: #00a4ff;
}

.banner .right dd strong{
	font-weight: 400;
	color: #7d7d7d;
}

.banner .right a{
	display: block;
	height: 32px;
	background-color: #00A4FF;
	text-align: center;
	line-height: 32px;
	font-size: 14px;
	color: #fff;
	border-radius: 15px;
}

/* 精品推荐 */
.recommend{
	display: flex;
	margin-top: 11px;
	padding: 0 20px;
	height: 60px;
	background-color: #fff;
	box-shadow: 0px 1px 2px 0px rgba(211, 211, 211, 0.5);
	line-height: 60px;
}

.recommend h3{
	font-size: 18px;
	color: #00A4FF;
	font-weight: 400;
}

.recommend ul{
	/* 除去标题和修改兴趣的尺寸,父级剩余尺寸都给ul,实现把修改兴趣挤到最右侧 */
	flex: 1;
	display: flex;
}

.recommend ul li a{
	padding: 0 24px;
	font-size: 18px;
	border-right: 1px solid #e0e0e0;
}

/* 鼠标悬停 */
.recommend ul li a:hover{
	color: #00A4FF;
}

/* 去掉最后一个内容区域的右边框 */
.recommend ul li:last-child a{
	border-right: 0;
}

.recommend .modify{
	font-size: 16px;
	color: #00A4FF;
}

/* 推荐课程 */
.course{
	margin-top: 15px;
}

/* 标题 公共类,与其他区域共用 */
.hd{
	display: flex;
	justify-content: space-between;
	height: 60px;
	line-height: 60px;
}

.hd h3{
	font-size: 21px;
	font-weight: 400;
}

.hd .more{
	padding-right: 20px;
	background: url(../images/more.png) no-repeat right center;
	font-size: 14px;
	color: #999;
}

/* 课程内容,公共类 */
.bd ul{
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	
} 

.bd li{
	margin-bottom: 14px;
	width: 228px;
	height: 271px;
	background-color: pink;
	
}

.bd li .pic {
	height: 156px;
}

.bd li .text{
	padding: 20px;
	height: 115px;
	background-color: #fff;
}

.bd li .text h4{
	margin-bottom: 13px;
	height: 40px;
	font-size: 14px;
	line-height: 20px;
	font-weight: 400;
}

.bd li .text p{
	font-size: 14px;
	line-height: 20px;
	color: #999;
}

.bd li .text p span{
	color: #fa6400;
}
.bd li .text p i{
	font-style: normal;
}

/* 前端开发工程师 */
.hd ul{
	display: flex;
}
.hd li{
	margin-right: 60px;
	font-size: 16px;
}

.hd li .active{
	color: #00A4FF;
}

.bd {
	display: flex;
	justify-content: space-between;
}

.bd .left{
	width: 228px;
	/* background-color: pink; */
}

.bd .right{
	width: 957px;
}

.bd .right .top{
	margin-bottom: 15px;
	height: 100px;
}

/* 版权 */
.footer{
	margin-top: 60px;
	padding-top: 60px;
	height: 273px;
	background-color: #fff;
}

.footer .wrapper{
	display: flex;
	justify-content: space-between;
}

.footer .left{
	width: 440px;
}

.footer .left p{
	margin-top: 24px;
	margin-bottom: 14px;
	font-size: 12px;
	line-height: 17px;
	color: #666;
}
.footer .left .download{
	display: block;
	width: 120px;
	height: 36px;
	border: 1px solid #00A4FF;
	text-align: center;
	line-height: 34px;
	font-size: 16px;
	color: #00A4FF;
}

.footer .right{
	display: flex;
}

.footer .right dl{
	margin-left: 130px;
}

.footer .right dt{
	margin-bottom: 12px;
	font-size: 16px;
	line-height: 23px;
}

.footer .right a{
	font-size: 14px;
	color: #666;
	line-height: 24px;
}

小结

整体来说不难,主要是对于盒子模型的理解,具体边距的相关排版与计算,对flex分布的使用。可以按照标题区、首页图、精品推荐、精品课程、前端开发、脚标信息这些模块,逐步开发学习。练习css的一些常用属性的使用。