小兔鲜儿项目pc客户端前端静态页面
一.效果图
二.文件和目录准备
-
新建index.html在根目录
-
新建css文件夹保存网站的样式,并新建以下css文件:
base.css:基础公共样式
common.css:该网站中多个网页相同模块的重复样式,如:头部,底部
index.css:首页样式
三.基础公共样式
场景:一般项目开始前,首先会去除掉浏览器默认样式,设置为当前项目需要的初始化样式
作用:防止不同浏览器中标签默认样式不同造成的影响,统一不同浏览器的默认显示效果,方便后续项目开发
文件:base.css
/* 去除常见标签默认的margin和padding */
body,
h1,
h2,
h3,
h4,
h5,
h6,
p,
ul,
ol,
li,
dl,
dt,
dd,
input {
margin: 0;
padding: 0;
}
/* 设置网页统一的字体大小,行高,字体相关属性 */
body {
font: 16px/1.5 "Helvetica Neue", Helvetica, Arial, "Microsoft Yahei",
"Hiragino Sans GB", "Heiti SC", "WenQuanYi Micro Hei", sans-serif;
color: #333;
}
/* 去除列表默认样式 */
ul,
ol {
list-style: none;
}
/* 去除默认的倾斜效果 */
em,
i {
font-style: normal;
}
/* 去除a标签默认的下划线,并设置默认的文字颜色 */
a {
text-decoration: none;
color: #333;
}
/* 设置img的垂直对齐方式为居中对齐,去除img默认下间隙 */
img {
vertical-align: middle;
}
/* 去除input默认样式 */
input {
border: none;
/* 去除获取焦点时默认的轮廓线 */
outline: none;
color: #333;
}
/* 左浮动 */
.fl {
float: left;
}
/* 右浮动 */
.fr {
float: right;
}
/* 双伪元素清除浮动法 */
.clearfix::before,
.clearfix::after {
content: "";
display: table;
}
.clearfix::after {
clear: both;
}
四.多个网页相同模块的重复样式
作用:网站中不同的网页有的部分样式相同,相同样式的部分可以link同一个css文件
例如:头部和底部:
文件:common.css
/* 版心的公共类 */
.container {
width: 1240px;
margin: 0 auto;
}
/* ---------快捷菜单模块:xtx-shortcut */
.xtx-shortcut {
height: 52px;
background-color: #333333;
}
.xtx-shortcut .container {
height: 52px;
/* ps */
/* background-color: skyblue; */
}
.xtx-shortcut .container li {
float: left;
line-height: 52px;
color: #666666;
}
.xtx-shortcut .container a {
margin: 0 16px;
color: #dcdcdc;
font-size: 14px;
}
.xtx-shortcut li:last-child a {
margin-right: 0;
}
.xtx-shortcut li:last-child a::before {
content: '';
display: inline-block;
width: 11px;
height: 16px;
background: url('../images/sprites.png') -160px -70px;
vertical-align: middle;
margin-right: 8px;
margin-top: -3px;
}
.xtx-main-nav {
height: 130px;
padding-top: 30px;
box-sizing: border-box;
/* ps */
/* background-color: pink; */
}
.xtx-main-nav .logo {
width: 207px;
height: 70px;
margin-left: 25px;
/* ps */
/* background-color: skyblue; */
}
.xtx-main-nav .logo a {
display: block;
width: 207px;
height: 70px;
background-image: url('../images/logo.png');
background-size: 100% 100%;
font-size: 0;
}
.xtx-main-nav nav li {
float: left;
height: 70px;
line-height: 70px;
margin-right: 48px;
}
.xtx-main-nav nav {
margin-left: 40px;
}
.xtx-main-nav nav a:hover {
color: #27ba9b;
border-bottom: 1px solid #27ba9b;
padding-bottom: 7px;
}
.xtx-main-nav .search {
width: 172px;
height: 30px;
/* ps */
/* background-color: orange; */
margin-top: 24px;
margin-left: 34px;
position: relative;
}
.xtx-main-nav .search::before {
content: '';
position: absolute;
top: 5px;
left: 2px;
width: 18px;
height: 18px;
background: url(../images/sprites.png) -80px -70px;
}
.xtx-main-nav .search input {
width: 172px;
height: 30px;
border-bottom: 2px solid #e7e7e7;
padding-left: 31px;
line-height: 0px;
}
.xtx-main-nav .cart {
width: 23px;
height: 23px;
background: url(../images/sprites.png) -120px -70px;
margin-top: 28px;
margin-left: 15px;
position: relative;
}
.xtx-main-nav .cart span {
position: absolute;
top: -5px;
right: -12px;
width: 20px;
height: 15px;
background-color: #e26237;
border-radius: 8px;
color: #fff;
font-size: 13px;
text-align: center;
line-height: 15px;
}
/* ------------------宣传服务 */
.xtx-service {
height: 174px;
background-color: #333333;
}
.xtx-service .container {
width: 1393px;
height: 173px;
border-bottom: 1px solid #434343;
/* ps */
/* background-color: pink; */
}
.xtx-service .container a {
float: left;
width: 33.33%;
height: 173px;
/* ps */
/* background-color: blue; */
font-size: 28px;
color: #fff;
text-align: center;
line-height: 173px;
}
.xtx-service .container a::before {
content: '';
display: inline-block;
width: 58px;
height: 58px;
margin-right: 19px;
background: url(../images/sprites.png) 0 0;
/* 垂直对齐方式 */
vertical-align: middle;
}
.xtx-service a:nth-child(2)::before {
background: url(../images/sprites.png) -130px 0;
}
.xtx-service a:nth-child(3)::before {
background: url(../images/sprites.png) -65px 0;
}
/* ---------------版权信息 */
.xtx-copyright {
height: 168px;
background-color: #333333;
}
.xtx-copyright .container {
height: 168px;
padding-top: 41px;
box-sizing: border-box;
/* ps */
/* background-color: pink; */
text-align: center;
font-size: 14px;
color: #999;
}
.xtx-copyright .container a {
color: #999;
}
.xtx-copyright .container p:first-child {
height: 35px;
}
五.首页样式
文件:index.css
.xtx-entry {
height: 500px;
background-color: #f5f5f5;
}
.xtx-entry .container {
position: relative;
height: 500px;
/* background-color: pink; */
}
.xtx-entry .container .category {
position: absolute;
top: 0;
left: 0;
width: 251px;
height: 500px;
background: rgba(0, 0, 0, .8);
}
.xtx-entry .category a {
color: #fff;
}
.xtx-entry .category li {
position: relative;
height: 50px;
line-height: 50px;
padding-left: 36px;
}
.xtx-entry .category li:hover {
background-color: #27ba9b;
}
.xtx-entry .category span {
font-size: 14px;
}
.xtx-entry .category span:first-child {
margin-left: 15px;
}
.xtx-entry .category a::after {
content: '';
position: absolute;
top: 19px;
right: 19px;
width: 6px;
height: 11px;
background: url(../images/sprites.png) -80px -110px;
}
.xtx-entry .prev {
position: absolute;
top: 228px;
left: 260px;
width: 45px;
height: 45px;
border-radius: 50%;
background: rgba(0, 0, 0, .2) url(../images/sprites.png) 13px -60px;
}
.xtx-entry .next {
position: absolute;
top: 228px;
right: 10px;
width: 45px;
height: 45px;
border-radius: 50%;
background: rgba(0, 0, 0, .2) url(../images/sprites.png) -23px -60px;
}
.xtx-entry .indicator {
position: absolute;
left: 680px;
bottom: 31px;
width: 110px;
height: 10px;
/* ps */
/* background-color: red; */
}
.xtx-entry .indicator li {
float: left;
width: 10px;
height: 10px;
margin-right: 15px;
background-color: rgba(255,255,255,.43);
border-radius: 50%;
}
.xtx-entry .indicator li:last-child {
margin-right: 0;
}
.xtx-entry .indicator li.active {
background-color: #fff;
}
/* ---------------------新鲜好物模块 */
.xtx-new-goods {
height: 520px;
/* ps */
/* background-color: pink; */
}
.xtx-new-goods .goods-hd {
height: 115px;
/* ps */
/* background-color: skyblue; */
line-height: 115px;
}
.xtx-new-goods .goods-list {
height: 405px;
/* ps */
/* background-color: orange; */
}
.xtx-new-goods .goods-hd h2 {
height: 115px;
font-size: 29px;
font-weight: 400;
}
.xtx-new-goods .goods-hd h2 span {
font-size: 16px;
color: #999;
}
.xtx-new-goods .goods-hd a {
color: #999;
}
.xtx-new-goods .goods-hd a::after {
content: '';
display: inline-block;
width: 7px;
height: 13px;
margin-left: 13px;
background: url(../images/sprites.png) 0 -110px;
vertical-align: middle;
}
.xtx-new-goods .goods-list li {
float: left;
width: 304px;
height: 405px;
background-color: #f0f9f4;
margin-right: 8px;
line-height: 1;
text-align: center;
}
.xtx-new-goods .goods-list li:last-child {
margin-right: 0;
}
.xtx-new-goods .goods-list img {
width: 100%;
}
.xtx-new-goods .goods-list h3 {
height: 40px;
margin-top: 22px;
font-size: 20px;
font-weight: 400;
}
.xtx-new-goods .goods-list p {
font-size: 23px;
color: #9a2e1f;
}
.xtx-new-goods .goods-list span {
font-size: 17px;
}
六.首页结构
文件:index.html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>小兔鲜儿-新鲜、惠民、快捷!</title>
<meta name="description" content="小兔鲜儿官网,致力于打造全球最大的食品、生鲜电商购物平台。">
<meta name="keywords" content="小兔鲜儿,食品,生鲜,服装,家电,电商,购物">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="./css/base.css">
<link rel="stylesheet" href="./css/common.css">
<link rel="stylesheet" href="./css/index.css">
</head>
<body>
<!-- 头部模块 -->
<header>
<!-- 快捷菜单模块 -->
<div class="xtx-shortcut">
<!-- 版心的盒子 -->
<nav class="container">
<ul class="fr">
<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>
</ul>
</nav>
</div>
<!-- 主导航模块 -->
<div class="xtx-main-nav container">
<!-- logo用h1标签包裹 -->
<h1 class="logo fl">
<a href="#">小兔鲜儿</a>
</h1>
<!-- 导航 -->
<nav class="fl">
<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="#">孕婴</a></li>
<li><a href="#">服装</a></li>
</ul>
</nav>
<!-- 搜素 -->
<div class="search fl">
<input type="search" placeholder="搜一搜">
</div>
<!-- 购物车 -->
<div class="cart fl">
<span>2</span>
</div>
</div>
</header>
<!-- 网站入口 -->
<div class="xtx-entry">
<div class="container">
<!-- 轮播图 -->
<ul class="banner">
<li>
<a href="#">
<img src="./uploads/banner_1.png" alt="">
</a>
</li>
</ul>
<aside class="category">
<ul>
<li><a href="#">生鲜 <span>水果</span> <span>蔬菜</span></a></li>
<li><a href="#">面食 <span>面点</span> <span>干果</span></a></li>
<li><a href="#">餐厨 <span>数码产品</span></a></li>
<li><a href="#">电器 <span>床品</span> <span>四件套</span> <span>被枕</span></a></li>
<li><a href="#">居家 <span>奶粉</span> <span>玩具</span> <span>辅食</span></a></li>
<li><a href="#">洗护 <span>洗发</span> <span>洗护</span> <span>美妆 </span></a></li>
<li><a href="#">孕婴 <span>奶粉</span> <span>玩具</span></a></li>
<li><a href="#">服饰 <span>女装</span> <span>男装</span></a></li>
<li><a href="#">杂货 <span>户外</span> <span>图书</span></a></li>
<li><a href="#">品牌 <span>品牌制造</span></a></li>
</ul>
</aside>
<!-- 左右按钮 -->
<a href="#" class="prev"></a>
<a href="#" class="next"></a>
<!-- 轮播图指示器 -->
<ol class="indicator">
<li></li>
<li></li>
<li class="active"></li>
<li></li>
<li></li>
</ol>
</div>
</div>
<!-- 新鲜好物模块 -->
<div class="xtx-new-goods container">
<!-- 好物模块头部 -->
<div class="goods-hd">
<!-- 左边的h2 -->
<h2 class="fl">
新鲜好物 <span>新鲜出炉 品质靠谱</span>
</h2>
<!-- 右边的a -->
<a href="#" class="fr">查看全部</a>
</div>
<!-- 好物模块的列表 -->
<ul class="goods-list">
<li>
<a href="#">
<img src="./uploads/new_goods_1.jpg" alt="">
<h3>睿米无线吸尘器</h3>
<p><span>¥</span> 899</p>
</a>
</li>
<li>
<a href="#">
<img src="./uploads/new_goods_2.jpg" alt="">
<h3>智能环绕3D空调</h3>
<p><span>¥</span> 1299</p>
</a>
</li>
<li>
<a href="#">
<img src="./uploads/new_goods_3.jpg" alt="">
<h3>广东软软糯米煲仔饭</h3>
<p><span>¥</span> 129</p>
</a>
</li>
<li>
<a href="#">
<img src="./uploads/new_goods_4.jpg" alt="">
<h3>罗西智能机械手表</h3>
<p><span>¥</span> 3399</p>
</a>
</li>
</ul>
</div>
<!-- 底部模块 -->
<footer>
<!-- 宣传服务 -->
<div class="xtx-service">
<div class="container">
<a href="#">价格亲民</a>
<a href="#">物流快捷</a>
<a href="#">品质新鲜</a>
</div>
</div>
<!-- 版权信息 -->
<div class="xtx-copyright">
<div class="container">
<p>
<a href="#">关于我们</a> |
<a href="#">帮助中心</a> |
<a href="#">售后服务</a> |
<a href="#">配送与验收</a> |
<a href="#">商务合作</a> |
<a href="#">搜索推荐</a> |
<a href="#">友情链接</a> |
</p>
<p>CopyRight @ 小兔鲜儿</p>
</div>
</div>
</footer>
</body>
</html>