精灵图
场景:项目中将多张小图,合成一张大图片,这个大图片就是精灵图
有点:减少服务器发送次数,减轻服务器的压力,提高页面加载速度
使用:
创建一个盒子,设置盒子的尺寸和小图尺寸相同
将精灵图设置为盒子的背景图
修改背景图位置
通过pxcook测量小图片的左上角坐标,分别取负值设置给盒子的background-position:x y
精灵图都用行内标签span等
移动背景图,水平,垂直 水平正数为右移动 垂直正数向下移动
background-position:0 0
背景图大小
作用:设置背景图的大小
background-size:宽 高
取值 数字+px ,
百分比 相对于当前盒子自身的宽高百分比
contain 包含,将背景图等比例缩放,直到不会超出盒子的最大(不一定会填满),图片的高或宽与盒子的尺寸相同,另一个方向会停止缩放
cover 覆盖,将背景图等比例缩放,直到刚好填满整个盒子没有空白
background-repeat 不自动填图
background连写:color image repeat position/size
盒子阴影
box-shadow
取值:h-shadow 必须,水平偏移量。允许负值
v-shadow 必须,垂直偏移量。允许负值
blur 可选,模糊度
spread 可选,阴影扩大
color 可选 阴影颜色
insert 可选,将阴影改成内部阴影
过渡
作用:让元素的样式慢慢的变化,配合hover使用,增强交互体验
属性名:transition
取值
过渡的属性:all:所有能过渡的属性都过渡;具体属性名如width:只有width过渡
过渡时长:数字+s(秒)
注意:
过渡需要默认状态和hover状态样式不同,才能有过渡效果
transition属性给需要过渡的元素本身加
transition属性设置在不同状态中,效果不同
1.给默认状态设置,鼠标移入移出都有过渡效果
2.给hover状态设置,鼠标移入有过渡效果,移出没有过渡效果
谁变化谁添加,在变化的主体上添加属性
骨架结构
<!DOCTYPE html>文档类型声明,告诉浏览器网页的html的版本(这里是html5) 写在页面的第一行,不属于html标签
<html lang="en">标识网页使用的语言
作用:搜索引擎归类+浏览器翻译
常见语言:zh-CN简体中文/en英文
<meta charset="UTF-8">标识网页使用的字符编码
作用:保存和打开的字符编码需要统一设置,否则会出现乱码
utf-8 万国码
gbk20000+汉字
<meta name="viewport" content="width=device-width, initial-scale=1.0">
宽度=设备宽度 :移动端网页的时候要用
<meta http-equiv="X-UA-Compatible" content="IE=edge">
解决ie兼容性问题
SEO三大标签
SEO:搜索引擎优化
作用:让网站在搜索引擎上的排名靠前
提升SEO的方法:
1.竞价排名
2.将网页制作成html后缀
3.标签语义化(在合适的地方使用合适的标签)
seo3大标签
title:网页的标题标签
description:网页描述标签(meta标签)
keywords:网页关键词标签(meta标签)
ico图标(一般放在根目录)简写:link-favicon
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
1. 新建项目文件夹xtx-pc-client,在VScode中打开
在实际开发中,项目文件夹不建议使用中文
所有项目相关文件都保存在xtx-pc-client目录中
2. 复制 favicon.ico 到xtx-pc-client 目录
一般习惯将ico图标放在项目根目录
3. 复制images和uploads 目录到xtx-pc-client目录中
images:存放网站 固定使用的图片素材,如:logo、样式修饰图片...等
uploads:存放网站非固定使用的图片素材,如:商品图片、宣传图片..等
4.新建index.html在根目录
5. 新建css文件夹保存网站的样式,并新建以下CSS文件:
base.css:基础公共样式(默认样式的清除)
common.css:该网站中多个网页相同模块的重复样式,如:头部、底部
index.css:首页样式
引入顺序 base common index
如果行内块和行内文字无法通过vertical-align或行高对齐,就定位
base.css
/* 去除默认margin,padding */
body,h1,h2,h3,h4,h5,h6,p,ul,ol,li,dl,dt,dd,input{
margin:0;
padding: 0;
}
/* 内减模式 */
*{
box-sizing:border-box;
}
/* 设置网页的统一字体大小,行高,字体系列相关属性 1.5倍行高*/
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;
}
common.css
/* 版心 */
.wrapper{
width: 1240px;
margin: 0 auto;
}
.shortcut{
height: 52px;
background-color: #333;
}
.shortcut .wrapper{
height: 52px;
}
.shortcut .wrapper ul{
float:right;
}
.shortcut .wrapper ul li{
float: left;
line-height: 52px;
}
.shortcut .wrapper ul a{
padding: 0 16px;
border-right:1px solid #666 ;
font-size: 14px;
color: #dcdcdc;
}
.shortcut .wrapper ul a span{
display: inline-block;
width: 13px;
height: 18px;
background-image: url(../image/1.png);
background-size: cover;
background-position: -4px 0;
vertical-align: middle;
margin-right: 10px;
}
.header{
margin: 30 auto;
height: 70px;
/* background-color: pink; */
}
.logo{
float: left;
width: 207px;
height: 70px;
/* background-color: black; */
}
/* seo优化 */
.logo h1{
width: 207px;
height: 70px;
}
.logo h1 a{
display: block;
width: 207px;
height: 70px;
background-image: url(../image/2.png);
background-size: cover;
font-size: 0;
/* 让字看不见,但是存在 */
}
.nav{
margin-left: 40px;
float: left;
height: 70px;
/* background-color: black; */
}
.nav li{
float: right;
line-height: 70px;
margin-right: 48px;
}
.nav li a{
padding-bottom: 7px;
}
.nav li a:hover{
color: green;
border-bottom: 1px solid green;
}
.search{
position: relative;
float: left;
margin-top: 24px;
margin-left: 34px;
width: 172px;
height: 30px;
/* background-color: black; */
border-bottom: 2px solid black;
}
.search input{
padding-left: 30px;
height: 28px;
width: 172px;
}
.search input::placeholder{
color: #666;
}
.search span{
position:absolute;
left: 2px;
top: 2px;
/* display: inline-block; */
width: 18px;
height: 18px;
background-color: pink;
background-image: url(../image/1.png);
background-position: 0 0;
background-size: cover;
}
.car{
position: relative;
float: left;
margin-top: 24px;
margin-left: 15px;
width: 23px;
height: 23px;
background-color: black;
background-image: url(../image/1.png);
background-size: cover;
background-position: 0 0;
}
.car span{
right: -13px;
top: -5px;
/* 因为是绝对定位,具备行内块特性 */
position: absolute;
width: 20px;
height: 15px;
background-color: #ff0000;
border-radius: 8px;
color: white;
font-size: 13px;
text-align: center;
line-height: 15px;
}
.footer{
height: 342px;
background-color: #333;
}
.footer .wrapper{
width: 1393px;
}
.footer .top{
padding-top: 59px;
padding-left: 135px;
height: 175px;
border-bottom: 3px solid #434343;
}
.footer .top li{
position: relative;
float: left;
margin-right: 300px;
width: 195px;
height: 58px;
/* background-color: pink; */
}
.footer .top li:last-child{
margin-right: 0;
}
.footer .top li::before{
/* display: inline-block; */
position: absolute;
top: 0;
left: 0;
content: '';
width: 58px;
height: 58px;
background-image: url(../image/1.png);
vertical-align: middle;
background-size: cover;
}
.footer .top li span{
color: aliceblue;
font-size: 28px;
margin-left: 67px;
}
.footer .bottom{
padding-top: 40px;
color: #999;
font-size: 14px;
text-align: center;
}
.footer .bottom a{
color: #999;
font-size: 14px;
}
index.css
/* banner */
.banner{
height: 500px;
background-color: #f5f5f5;
}
.banner .wrapper{
position: relative;
height: 500px;
background-color: pink;
}
.banner li a img{
width: 1240px;
height: 500px;
}
.banner .aside{
position: absolute;
top: 0;
left: 0;
width: 250px;
height: 500px;
background-color:rgba(255, 255, 255, 0.9)
}
.banner .aside li{
height: 50px;
line-height: 50px;
}
.banner .aside a{
position: relative;
padding-left:35px ;
padding-right: 19px;
display: block;
height: 50px;
color: #160303;
}
.banner .aside li a span{
font-size: 14px;
margin-left: 15px;
}
.banner .aside li a:hover{
background-color: #54d843;
}
.banner .aside li a::after{
position: absolute;
top: 20px;
right: 14px;
content: '';
width: 6px;
height: 11px;
background-image: url(../image/1.png);
background-size: cover;
background-position: -3px 0;
}
.prev,.next{
position: absolute;
top: 228px;
width: 45px;
height: 45px;
background-color: rgba(255, 255, 255, 0.9);
border: 50%;
background-image: url(../image/1.png);
background-size: cover;
}
.prev{
left: 260px;
background-position: 0 0;
}
.next{
right: 10px;
background-position: 0 0;
}
.banner ol{
position: absolute;
left: 680px;
bottom: 30px;
width: 200px;
height: 10px;
/* background-color: plum; */
}
.banner ol li{
float: left;
width: 10px;
height: 10px;
margin-right: 24px;
background-color: rgba(255, 255, 255, 0.6);
border-radius: 50%;
}
.banner ol .current{
background-color: #fff;
}
.goods .hd{
height: 114px;
/* background-color: pink; */
line-height: 114px;
}
.goods .hd h2{
float: left;
font-size: 29px;
font-weight: 400;
height: 114px;
}
.goods .hd h2 span{
margin-left: 34px;
font-size: 16px;
color: #999;
}
.goods .hd a{
float: right;
color: #999;
}
.goods .hd a::after{
content: '';
display: inline-block;
margin-left: 13px;
width: 7px;
height: 13px;
background-image: url(../image/1.png);
background-size: cover;
background-position: -3px 0;
vertical-align: middle;
}
.goods .bd li{
position: relative;
float: left;
margin-right: 8px;
width: 304px;
height: 405px;
background-color: #97ce90;
text-align: center;
}
.goods .bd li:last-child{
margin-right: 0;
}
.goods .bd li img{
width: 304px;
}
.goods .bd li h3{
margin-top: 20px;
margin-bottom: 10px;
font-size: 20px;
font-weight: 400;
}
.goods .bd li div{
color: rgb(247, 43, 43);
font-size: 17px;
}
.goods .bd li div span{
font-size: 23px;
}
.goods .bd li b{
position: absolute;
left: 13px;
top: 18px;
width: 28px;
height: 51px;
color: #f1562b;
border: 1px solid #f1ff55;
line-height: 26px;
}
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./css/base.css">
<link rel="stylesheet" href="./css/common.css">
<link rel="stylesheet" href="./css/index.css">
<title>fistlweb</title>
</head>
<body>
<!-- 快捷菜单 -->
<div class="shortcut">
<div class="wrapper">
<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="#"><span></span>请先登录</a></li>
</ul>
</div>
</div>
<!-- 头部 -->
<div class="header wrapper">
<div class="logo">
<h1><a href="">小兔仙儿</a></h1>
</div>
<div class="nav">
<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>
</div>
<div class="search">
<input type="text" placeholder="搜一搜">
<span>
</span>
</div>
<div class="car">
<span>2</span>
</div>
</div>
<!-- banner -->
<div class="banner">
<div class="wrapper">
<!-- 有多少个图就有多少个li -->
<ul>
<li>
<a href="#"><img src="./image/3.jpg" alt=""></a>
</li>
</ul>
<!-- 侧导航 -->
<div class="aside">
<ul>
<li><a href="#">生鲜 <span>水果 蔬菜</span></a></li>
<li><a href="#">生鲜 <span>水果 蔬菜</span></a></li>
<li><a href="#">生鲜 <span>水果 蔬菜</span></a></li>
<li><a href="#">生鲜 <span>水果 蔬菜</span></a></li>
<li><a href="#">生鲜 <span>水果 蔬菜</span></a></li>
<li><a href="#">生鲜 <span>水果 蔬菜</span></a></li>
<li><a href="#">生鲜 <span>水果 蔬菜</span></a></li>
<li><a href="#">生鲜 <span>水果 蔬菜</span></a></li>
<li><a href="#">生鲜 <span>水果 蔬菜</span></a></li>
<li><a href="#">生鲜 <span>水果 蔬菜</span></a></li>
</ul>
</div>
<!--箭头 -->
<div class="prev">
</div>
<div class="next">
</div>
<!-- 圆点 当前状态 current/active -->
<ol>
<li></li>
<li></li>
<li class="current"></li>
<li></li>
<li></li>
</ol>
</div>
</div>
<!-- 新鲜好物-->
<div class="goods wrapper">
<div class="hd">
<h2>新鲜好物<span>新鲜出炉 好物推荐</span></h2>
<a href="#">查看全部</a>
</div>
<div class="bd clearfix">
<ul>
<li><a href="#"><img src="./image/2.png" alt="">
<h3>你好</h3>
<div>¥<span>1299</span>
<b>新品</b>
</div>
<li><a href="#"><img src="./image/2.png" alt="">
<h3>你好</h3>
<div>¥<span>1299</span><b>新品</b></div>
<li><a href="#"><img src="./image/2.png" alt="">
<h3>你好</h3>
<div>¥<span>1299</span><b>新品</b></div>
<li><a href="#"><img src="./image/2.png" alt="">
<h3>你好</h3>
<div>¥<span>1299</span><b>新品</b></div>
</ul>
</div>
</div>
<!-- 版权 -->
<div class="footer">
<div class="wrapper">
<div class="top">
<ul>
<li>
<!-- 用伪元素添加标签,是行内显示 -->
<span>价格亲民</span>
</li>
<li> <span>价格亲民</span></li>
<li> <span>价格亲民</span></li>
</ul>
</div>
<div class="bottom">
<p>
<a href="#">关于我们</a>|
<a href="#">关于我们</a>|
<a href="#">关于我们</a>|
<a href="#">关于我们</a>|
<a href="#">关于我们</a>|
<a href="#">关于我们</a>|
<a href="#">关于我们</a>
</p>
<p>dsadasd@dasdas</p>
</div>
</div>
</div>
</body>
</html>
效果: