CSS3练习–电商web

9,379次阅读
没有评论

共计 6870 个字符,预计需要花费 18 分钟才能阅读完成。

免责声明:本文仅做分享!

 

目录

 小练 – 小兔鲜儿

目录构建

SEO 三大标签

Favicon 图标

布局网页

版心

快捷导航(shortcut)

logo

导航

搜索

购物车

服务区

帮助区

版权区

中间(banner)

新鲜好物区

人气推荐区

热门品牌区

生鲜区

最新专题区

base.css(清除默认样式)



小兔鲜儿 – 新鲜 惠民 快捷!(itheima.net)

SEO、Favicon、小兔鲜儿


 小练 – 小兔鲜儿

(电商 web)

目录构建

CSS3 练习 -- 电商 web


SEO 三大标签

SEO: 搜索引擎优化 ,提升网站百度搜索排名。

提升 SEO 的常见方法:

1. 竞价排名(花米)

2. 将网页制作成 html 后缀

3. 标签语义化(在合适的地方使用合适的标签)

4. ……

网页头部 SEO 标签:

• title:网页标题标签

• description:网页描述

• keywords:网页关键词

  
  
  
  
  
   小兔鲜儿 - 新鲜、惠民、快捷!

Favicon 图标

网页图标,出现在浏览器标题栏,增加网站辨识度。

.ico


  

布局网页

版心

版心居中

/* 版心 */
.wrapper {
  margin: 0 auto;
  width: 1240px;   /* 自己测量 */
}

快捷导航(shortcut)

CSS3 练习 -- 电商 web

通栏 > 版心 > 导航 ul > li > a

flex-end(右对齐)

— 给 a 加边框线,而不给 li 加,让 a 的高与字的高一样大,高。CSS3 练习 -- 电商 web


(头部的盒子尺寸,要整体布局。)

CSS3 练习 -- 电商 web

.header > logo + 导航(nav)+ 搜索(search)+ 购物车(cart)

CSS3 练习 -- 电商 web

display: block;  转成块级,这样就可以设置宽高。

CSS3 练习 -- 电商 web


导航

a 有底部 10px 间距。

CSS3 练习 -- 电商 web


搜索

input 默认样式(浏览器默认 先 生效默认样式!)


购物车



/* 购物车 */
.cart {
  position: relative;
  margin-top: 32px;
}

.cart .iconfont {font-size: 24px;}

.cart i {
  position: absolute;
  /* 相对定位 */
  top: 1px;
  /* right 定位右对齐:如果文字多了,向左撑开,可能盖住其他的内容 */
  /* right: 1px; */
  /* left 定位左对齐:文字多了,向右撑开 */
  left: 15px;
  /* 一般要向左对齐,向右撑开,所以不右对齐 */


  /* 宽度不给,将来由内容撑开 */

  padding: 0 6px;
  height: 15px;
  background-color: #E26237;
  border-radius: 8px;
  font-size: 14px;
  color: #FFFEFE;
  line-height: 15px;
  /* 文字垂直居中,与高度一致 */
}

— 因为底部与头部类似,所以先完成底部。

 

  
  

 


/* 底部 */
.footer {
  height: 580px;
  background-color: #F5F5F5;
}


/* 服务 */
.service {
  padding: 60px 0;
  height: 178px;
  border-bottom: 1px solid #E8E8E8;
}

.service ul {
  display: flex;
  justify-content: space-evenly;
}

.service li {
  display: flex;
  width: 190px;
  height: 58px;
  /* background-color: pink; */
}

.service li h5 {
  margin-right: 20px;
  width: 58px;
  height: 58px;
  background-image: url(../images/sprite.png);
}

.service li p {
  font-size: 28px;
  line-height: 58px;
}

.service li:nth-child(2) h5 {background-position: 0 -58px;}

.service li:nth-child(3) h5 {background-position: 0 -116px;}

.service li:nth-child(4) h5 {background-position: 0 -174px;}

/* 帮助中心 */
.help {
  display: flex;
  justify-content: space-between;
  padding-top: 60px;
  height: 300px;
  /* background-color: pink; */
}

/* left */
.help .left {display: flex;}

.help .left dl {margin-right: 84px;}

.help .left dl:last-child {margin-right: 0;}

.help .left dt {
  margin-bottom: 30px;
  font-size: 18px;
}

.help .left dd {margin-bottom: 10px;}

.help .left a {color: #969696;}

.help .left .iconfont {color: #5EB69C;}

/* right */
.help .right ul {display: flex;}

.help .right li:first-child {margin-right: 55px;}

.help .right .pic {
  margin-bottom: 10px;
  width: 120px;
  height: 120px;
}

.help .right p {
  color: #969696;
  text-align: center;
}

/* 版权 */
.copyright {text-align: center;}

.copyright p {
  margin-bottom: 10px;
  color: #A1A1A1;
}

.copyright p a {
  margin: 0 10px;
  color: #A1A1A1;
}

服务区

– 注意 CSS 精灵(雪碧图)的应用。


帮助区

分左右两部分. 


版权区

小竖线 直接打 |  


中间(banner)


通栏 > 版心 > 轮播图(ul.pic)+ 侧导航(subnav > ul)+ 圆点指示器(ol)

        定位(子绝父相)

 侧导航 

 右下角圆点指示器  ol > li > i(li 是大圆,i 是小圆)

 

/* banner */
.banner {
  height: 500px;
  background-color: #F5F5F5;
}

.banner .wrapper {
  position: relative;
  height: 500px;
  background-color: pink;
  overflow: hidden;
  /* 隐藏溢出 */
}

/* 图片 */
.banner .pic {
  display: flex;
  /* flex 布局,父级宽度不够,子级被挤小,不想挤小,增大父级尺寸 */
  width: 3720px;
}

/* 侧导航 */
.subnav {
  position: absolute;
  left: 0;
  top: 0;
  width: 250px;
  height: 500px;
  background-color: rgba(0, 0, 0, 0.42);
}

.subnav li {
  display: flex;
  justify-content: space-between;
  padding-left: 30px;
  padding-right: 12px;
  height: 50px;
  /* background-color: pink; */
  line-height: 50px;
  color: #fff;

  cursor: pointer;
}

/* a 所有都是小字,分类是大字 */
.subnav li a {
  margin-right: 5px;
  font-size: 14px;
  color: #fff;
}

.subnav li .classify {
  margin-right: 14px;
  font-size: 16px;
}

.subnav li .iconfont {font-size: 14px;}

.subnav li:hover {background-color: #00BE9A;}

/* 圆点指示器 */
.banner ol {
  position: absolute;
  bottom: 17px;
  right: 16px;
  display: flex;
}

.banner ol li {
  margin-left: 8px;
  width: 22px;
  height: 22px;
  /* background-color: pink; */
  border-radius: 50%;
  cursor: pointer;
}

.banner ol i {
  display: block;
  margin: 4px;
  width: 14px;
  height: 14px;
  background-color: rgba(255, 255, 255, 0.5);
  border-radius: 50%;
}

/* 选中:li 半透明;i 白色 */
.banner ol .current {background-color: rgba(255, 255, 255, 0.5);
}

.banner ol .current i {background-color: #fff;}

 


新鲜好物区

标题(title)+ 内容(bd)

(样式共用)

标题:

内容:


人气推荐区

与上面类似


热门品牌区

箭头 – 定位。

 


 

生鲜区

标题 + 内容

鼠标悬停显示 —》过渡效果。

/* 生鲜 */
.fresh .title {
  margin-top: 60px;
  margin-bottom: 20px;
}

.title .right {display: flex;}

.title .right ul {
  display: flex;
  margin-top: 10px;
  margin-right: 58px;
}

.title .right ul a {
  display: block;
  margin-left: 6px;
  padding: 0 7px;
  height: 20px;
  /* background-color: pink; */
  line-height: 20px;
}

.title .right ul .active {
  background-color: #00BE9A;
  color: #fff;
}

/* 生鲜内容 */
.content {
  display: flex;
  justify-content: space-between;
}

.content .left {
  width: 248px;
  height: 610px;
  /* background-color: pink; */
}

.content .right {
  width: 968px;
  height: 610px;
  /* background-color: pink; */
}

.content .right ul {
  display: flex;
  flex-wrap: wrap;
}

.content .right li {
  position: relative;
  padding: 10px 21px 0;
  width: 242px;
  height: 305px;
  border: 2px solid #fff;

  /* 为了隐藏绿色 cover */
  overflow: hidden;
}

/* 产品内容 */
.content .pic {
  width: 200px;
  height: 180px;
}

.content .info {
  margin-top: 14px;
  margin-bottom: 5px;
  height: 60px;
  line-height: 19px;
}

.content .price {color: #AF2F22;}

.content .price span {
  margin-left: 5px;
  font-size: 22px;
}

/* 产品底部绿色区域 */
.content li .cover {
  position: absolute;
  left: 0;
  /* bottom: 0; */
  bottom: -86px;
  padding-top: 15px;
  width: 242px;
  height: 84px;
  background-color: #00BE9A;
  text-align: center;
  color: #fff;
  transition: all 0.5s;
}

.content .cover p:nth-child(1) {font-size: 18px;}

.content .cover p:nth-child(2) {
  margin: 3px auto 6px;
  width: 120px;
  height: 1px;
  background-color: rgba(255, 255, 255, 0.11);
}

.content .cover p:nth-child(3) {font-size: 13px;}

.content .cover p:nth-child(3) .iconfont {font-size: 14px;}

/* 鼠标悬停到 li,显示 cover,改变位置 */
.content .right li:hover .cover {bottom: 0;}

.content .right li:hover {border: 2px solid #00BE9A;}

最新专题区

ul > li * 3 

 渐变???颜色



/* 最新专题 */
.topic {margin-bottom: 40px;}

.topic .title {margin-top: 100px;}

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

.topic-bd li {
  width: 405px;
  height: 355px;
  /* background-color: pink; */
}

.topic-bd .pic {
  position: relative;
  width: 405px;
  height: 288px;
}

.topic-bd .txt {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 15px;
  width: 405px;
  height: 67px;
  /* background-color: skyblue; */
  font-size: 14px;
  color: #666;
}

.topic-bd .txt .left {display: flex;}

.topic-bd .txt .left p {margin-right: 20px;}

.topic-bd .txt .left p:nth-child(1) i {color: #AA2113;}

/* 定位区域 - 文字 */
.topic-bd .cover {
  position: absolute;
  left: 0;
  bottom: 0;

  display: flex;
  justify-content: space-between;
  align-items: center;

  padding: 0 15px;
  width: 405px;
  height: 90px;
  background-image: linear-gradient(180deg, rgba(137, 137, 137, 0.00) 0%, rgba(0, 0, 0, 0.90) 100%);
}

.topic-bd .cover .left {color: #fff;}

.topic-bd .cover .left h4 {
  margin-bottom: 6px;
  font-size: 20px;
}

.topic-bd .cover .right {
  padding: 0 7px;
  height: 25px;
  background-color: #fff;
  color: #AA2113;
  font-size: 15px;
}

.topic-bd .cover .right span {font-size: 18px;}

base.css(清除默认样式)

/* 去除常见标签默认的 margin 和 padding */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* 设置网页统一的字体大小、行高、字体系列相关属性 */
body {
  font: 16px/1.5  "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 {
  width: 100%;
  height: 100%;
  vertical-align: middle;
}

/* 去除 input 默认样式 */
input {
  border: none;
  outline: none;
  color: #333;
}

h1,
h2,
h3,
h4,
h5,
h6 {font-weight: 400;}


原文地址: CSS3 练习 – 电商 web

    正文完
     0
    Yojack
    版权声明:本篇文章由 Yojack 于2024-10-14发表,共计6870字。
    转载说明:
    1 本网站名称:优杰开发笔记
    2 本站永久网址:https://yojack.cn
    3 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
    4 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
    5 本站所有内容均可转载及分享, 但请注明出处
    6 我们始终尊重原创作者的版权,所有文章在发布时,均尽可能注明出处与作者。
    7 站长邮箱:laylwenl@gmail.com
    评论(没有评论)