您的位置:首页 > 汽车 > 新车 > 社区团购卖货小程序_c2b模式是什么意思啊_去哪里找需要推广的app_百度广告联盟

社区团购卖货小程序_c2b模式是什么意思啊_去哪里找需要推广的app_百度广告联盟

2025/4/16 22:31:58 来源:https://blog.csdn.net/artist123abbb/article/details/144982064  浏览:    关键词:社区团购卖货小程序_c2b模式是什么意思啊_去哪里找需要推广的app_百度广告联盟
社区团购卖货小程序_c2b模式是什么意思啊_去哪里找需要推广的app_百度广告联盟

视频参考:B站Pink老师
今天是CSS学习的第十二天,今天开始的笔记对应Pink老师课程中的CSS第七天的内容。
本节重点:CSS高级技巧

本章目录

    • 本节目标
    • 1. 精灵图
      • 1.1 为什么需要精灵图
      • 1.2 精灵图使用
      • 案例:拼出自己的名字
    • 2. 字体图标
      • 2.1 字体图标的产生
      • 2.2 字体图标的优点
      • 2.3 字体图标下载
      • 2.4 字体图标的引入
      • 2.5 字体图标的追加
    • 3. CSS三角
    • 4. CSS用户界面样式
      • 什么是界面样式
      • 4.1 鼠标样式 cursor
      • 4.2 轮廓线 outline
      • 4.3 防止拖拽文本域resize
    • 5. vertical-align属性应用
      • 5.1 图片、表单、文字对齐
      • 5.2 解决图片底部默认空白缝隙问题
    • 6. 溢出的文字省略号显示
      • 6.1 单行文本溢出显示省略号
      • 6.2 多行文本溢出显示省略号
    • 7. 常见布局技巧
      • 7.1 margin负值的运用
      • 7.2 文字围绕浮动元素
      • 7.3 行内块元素的妙用
      • 7.4 CSS三角强化
    • 8. CSS初始化

本节目标

  • 能够使用精灵图
  • 能够使用字体图标
  • 能够写出CSS三角
  • 能够写出常见的CSS用户界面样式
  • 能够说出常见的布局技巧

1. 精灵图

1.1 为什么需要精灵图

其目的是为了有效减少服务器接收和发送请求的次数,提高页面加载速度。
精灵图样式如下:
在这里插入图片描述

1.2 精灵图使用

参考代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>.box1 {width: 60px;height: 60px;/* background-color: pink; */margin: 100px auto;background: url(images/sprites.png) -182px 0 no-repeat;/* background-position: -182px 0; */}.box2 {width: 27px;height: 25px;background: url(images/sprites.png) -155px -106px no-repeat;margin: 200px;}</style>
</head><body><div class="box1"></div><div class="box2"></div>
</body></html>

结果展示:
在这里插入图片描述

核心总结:

  • 精灵图主要针对于小的背景图片使用
  • 主要借助于背景位置来实现background-position
  • 一般情况下精灵图都是负值(注意方向与正负的对应)

案例:拼出自己的名字

参考代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>span {display: inline-block;background: url(images/abcd.jpg) no-repeat;}.a {width: 110px;height: 118px;background-color: pink;background-position: 0 -9px;}.u {width: 111px;height: 110px;background-position: -475px -422px;}.d {width: 97px;height: 115px;background-position: -364px -9px;}.i {width: 60px;height: 108px;background-position: -327px -142px;}</style>
</head><body><span class="a">a</span><span class="u">u</span><span class="d">d</span><span class="i">i</span>
</body></html>

这里可以根据自己想选择的字母,自己调整参数。
结果展示:
在这里插入图片描述

2. 字体图标

2.1 字体图标的产生

使用场景:主要用于显示网页中通用、常用的一些小图标
精灵图有很多优点,但其缺点明显:

  • 图片文件较大
  • 图片本身放大和缩小会失真
  • 一旦图片制作完毕想要更换很复杂
    所以出现了字体图标iconfont
    字体图标可以为前端工程师提供一种方便高效的图标使用方式,展示的虽然是图标,但其本质属于字体

2.2 字体图标的优点

  • 轻量级:减少服务器请求,渲染速度快。

  • 灵活性:本质是文字,可以随意改变颜色、产生阴影、透明效果、旋转等。

  • 兼容性:几乎支持所有浏览器。
    注:字体图标不能替代精灵技术,只是对工作中图标部分技术的提升和优化。
    总结:

  • 如果遇到一些结构样式简单的小图标。用字体图标。

  • 如果遇到一些结构和样式复杂一点的小图片,用精灵图。

2.3 字体图标下载

推荐以下两个网站:
icomoon字库:http://icomoon.io
阿里iconfont字库:http://www.iconfont.cn/

2.4 字体图标的引入

注意:下载完毕后不要删除源文件,后续需要使用
使用过程如下:

  • 把下载包里的fonts文件夹放入页面根目录下
  • 在CSS样式中全局声明字体(写到style中)这段声明可以在下载的字体文件中的style.css中找到。
    在这里插入图片描述
  • 在html标签内添加小图标
    在这里插入图片描述
    添加的小图标是图上红圈圈住的地方。
  • 设计样式即可

参考代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>/*字体声明*/@font-face {font-family: 'icomoon';src: url('fonts/icomoon.eot?p4ssmb');src: url('fonts/icomoon.eot?p4ssmb#iefix') format('embedded-opentype'),url('fonts/icomoon.ttf?p4ssmb') format('truetype'),url('fonts/icomoon.woff?p4ssmb') format('woff'),url('fonts/icomoon.svg?p4ssmb#icomoon') format('svg');font-weight: normal;font-style: normal;font-display: block;}span {font-family: 'icomoon';font-size: 100px;color: pink;}</style>
</head><body><span></span><span></span>
</body></html>

效果展示:
在这里插入图片描述

2.5 字体图标的追加

在import icons中上传原压缩包中的selection.json,然后选中自己想要的新的图标,重新下载压缩包替换原文件即可。
在这里插入图片描述
在这里插入图片描述

3. CSS三角

一些常见三角形用CSS画出来即可,不必做成图片或字体图标。示意图如下:
在这里插入图片描述
想让其变为三角形代码如下:

div {width: 0;height: 0;/*下面两句为了适配低版本浏览器,可写可不写*/line-height: 0;font-size: 0;border: 50px solid transparent;border-left-color: pink;}

参考代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>.box1 {width: 0;height: 0;/* border: 10px solid pink; */border-top: 10px solid pink;border-right: 10px solid red;border-bottom: 10px solid blue;border-left: 10px solid green;}.box2 {width: 0;height: 0;border: 50px solid transparent;border-left-color: pink;margin: 100px auto;}.jd {position: relative;width: 120px;height: 249px;background-color: pink;}.jd span {position: absolute;right: 15px;top: -9px;width: 0;height: 0;/*为了照顾兼容性*/line-height: 0;font-size: 0;border: 5px solid transparent;border-bottom-color: pink;}</style>
</head><body><div class="box1"></div><div class="box2"></div><!-- <div class="jd"><span></span></div> -->
</body></html>

结果展示:
在这里插入图片描述
相当于只留下了左边三角。
案例:京东三角
代码:去掉上面的div和span注释
效果:
在这里插入图片描述
我们做的就是三角和长方形盒子的结合。

4. CSS用户界面样式

什么是界面样式

所谓界面样式就是更改一些用户操作样式,以更好提升用户体验。

  • 更改用户的鼠标样式
  • 表单轮廓
  • 防止表单域拖拽

4.1 鼠标样式 cursor

 li {cursor: pointer;}

设置或检索在对象上移动的鼠标指针采用何种系统预定义的光标形状

属性值描述
default小白,默认
pointer小手
move移动
text文本
not-allowed禁止

参考代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head><body><ul><li style="cursor: default;">我是默认的小白鼠样式</li><li style="cursor: pointer;">我是鼠标小手样式</li><li style="cursor: move;">我是鼠标移动样式</li><li style="cursor: text;">我是鼠标文本样式</li><li style="cursor: not-allowed;">我是鼠标禁止样式</li></ul>
</body></html>

结果展示:
在这里插入图片描述
这里截图无法显示效果,结果就是放在不同的语句上,鼠标会变成不同的形状。

4.2 轮廓线 outline

给表单添加outline: 0;或者outline:none;样式之后,就可以去掉默认的蓝色边框。

input { outline: none;}

4.3 防止拖拽文本域resize

textarea {resize:none;}

注:<textarea></textarea>最好在一行,不然会出现文本域的文字输入部分距离最开始有很大空白的问题。
4.2和4.3的参考代码

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>input,textarea {outline: none;}textarea {resize: none;}</style>
</head><body><!--1.取消表单轮廓--><input type="text"><!--2.防止拖拽文本域--><textarea name="" id=""></textarea>
</body></html>

结果展示:
修改前:
在这里插入图片描述
修改后:
在这里插入图片描述

5. vertical-align属性应用

场景:用于设置图片/表单(行内块元素)和文字垂直对齐。
官方解释:用于设置一个元素的垂直对齐方式,只针对行内元素/行内块元素有效。
语法:

vertical-align: baseline|top|middle|bottom;
描述
baseline默认。基线对齐。
top与行内最高元素顶端对齐
middle放置父元素中部
bottom行元素顶端与最低元素顶端对齐

5.1 图片、表单、文字对齐

图片、表单都属于行内块元素,默认的vertical-align是基线对齐。
垂直对齐设置vertical-align: middle;即可

5.2 解决图片底部默认空白缝隙问题

bug:图片底侧会有1个空白缝隙,原因是行内块元素会和文字基线对齐。
两种方法解决:

  • 给图片添加vertical-align:middle|top|bottom等。(推荐使用)
  • 把图片转换为块级元素 display:block;(这样就不涉及基线对齐方法,因为转换为了块级元素)

参考代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>div {border: 2px solid red;}img {/* vertical-align: bottom; */display: block;}</style>
</head><body><div><img src="images/ldh.jpg" alt=""></div>
</body></html>

结果展示:
在这里插入图片描述
可以看到图片和红色边框中间没有空白缝隙了。

6. 溢出的文字省略号显示

6.1 单行文本溢出显示省略号

单行文本溢出显示省略号,必须满足三个条件:

            /*强制一行显示,默认normal自动换行*/white-space: nowrap;/*溢出部分隐藏*/overflow: hidden;/*文字用省略号替代超出部分*/text-overflow: ellipsis;

参考代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>div {width: 150px;height: 80px;background-color: pink;margin: 100px auto;/*显示不开,自动换行*//* white-space: normal; *//*强制一行显示*/white-space: nowrap;/*溢出部分隐藏*/overflow: hidden;/*省略号*/text-overflow: ellipsis;}</style>
</head><body><div>啥也不说,此处省略一万字</div>
</body></html>

结果展示:
在这里插入图片描述

6.2 多行文本溢出显示省略号

多行文本溢出显示省略号,有较大兼容性问题,适合于webkit浏览器或移动端(移动端大部分是webkit内核)

            overflow: hidden;text-overflow: ellipsis;/*弹性伸缩盒子模型显示*/display: -webkit-box;/*限制在一个块元素显示的文本行数*/-webkit-line-clamp: 3;/*设置或检索伸缩盒对象的子元素排列方式*/-webkit-box-orient: vertical;

这个效果更推荐后台人员来做,这里用的时候直接复制即可,但要理解每句的意思。

参考代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>div {width: 150px;height: 65px;background-color: pink;margin: 100px auto;overflow: hidden;text-overflow: ellipsis;/*弹性伸缩盒子模型显示*/display: -webkit-box;/*限制在一个块元素显示的文本行数*/-webkit-line-clamp: 3;/*设置或检索伸缩盒对象的子元素排列方式*/-webkit-box-orient: vertical;}</style>
</head><body><div>啥也不说,此处省略一万字,啥也不说,此处省略一万字啥也不说,此处省略一万字</div>
</body></html>

结果展示:
在这里插入图片描述

7. 常见布局技巧

7.1 margin负值的运用

  1. 让每个盒子margin往左侧移动-1px加margin-left:-1px;

参考代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>ul li {position: relative;float: left;list-style: none;width: 150px;height: 200px;border: 1px solid red;margin-left: -1px;}ul li:hover {/*如果盒子没有定位,鼠标经过添加相对定位即可*//* position: relative; *//*如果li都有定位,则利用z-index提高层级*/z-index: 1;border: 1px solid blue;}</style>
</head><body><ul><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li></ul>
</body></html>

结果展示:
在这里插入图片描述

有一个很奇怪的问题,按照代码应该全部是细线框,但是有些显示就是看起来很粗,并且更换电脑和浏览器之后不同位置的线框会看起来很粗,如果有人知道是为什么,可以在评论区告诉我一下,谢谢啦:)

  1. 鼠标经过某个盒子的时候,提高当前盒子的层级即可(如果没有定位,则加相对定位,保留位置;如果有定位,则加z-index)
    如果不提高层级显示效果如下:
    在这里插入图片描述
    显示不完全,所以需要提高层级。

7.2 文字围绕浮动元素

巧妙运用浮动元素不会压住文字的特性。

参考代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>* {margin: 0;padding: 0;}.box {width: 300px;height: 70px;background-color: pink;margin: 0 auto;padding: 5px;}.pic {float: left;width: 120px;height: 60px;/* background-color: blue; */margin-right: 5px;}.pic img {width: 100%;}</style>
</head><body><div class="box"><div class="pic"><img src="images/img.png" alt=""></div><p>【集锦】热身赛-巴西0-1秘鲁 内马尔替补 两人血染赛场</p></div>
</body></html>

结果展示:
在这里插入图片描述
浮动后,文字会自动环绕,而不需要单独设置格式。

7.3 行内块元素的妙用

给父盒子添加text-align: center;那么其中行内元素、行内块元素都会水平居中。

参考代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>* {margin: 0;padding: 0;}.box {text-align: center;}.box a {display: inline-block;width: 36px;height: 36px;background-color: #f7f7f7;border: 1px solid #ccc;text-align: center;line-height: 36px;text-decoration: none;color: #333;font-size: 14px;}.box .prev,.box .next {width: 85px;}.box .current,.box .elp {background-color: #fff;border: none;}.box input {height: 36px;width: 45px;border: 1px solid #ccc;outline: none;}.box button {width: 60px;height: 36px;background-color: #f7f7f7;border: 1px solid #ccc;}</style>
</head><body><div class="box"><a href="#" class="prev">&lt;&lt;上一页</a><a href="#" class="current">2</a><a href="#">3</a><a href="#">4</a><a href="#">5</a><a href="#">6</a><a href="#" class="elp">...</a><a href="#" class="next">&gt;&gt;下一页</a>到第<input type="text">页<button>确定</button></div>
</body></html>

结果展示:
在这里插入图片描述
用上述方法将其排列在一行且水平居中。

7.4 CSS三角强化

三角强化是想实现下面效果:
在这里插入图片描述
原理解释一个矩形加一个三角组合而成
首先,我们需要一个直角三角形,做法如下:

            width: 0;height: 0;border-color: transparent #fff transparent transparent;border-style: solid;border-width: 24px 10px 0 0;

完整代码如下:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>.box1 {width: 0;height: 0;/*把上边框调大*//* border-top: 100px solid transparent;border-right: 50px solid skyblue; *//*左边和下边的边框宽度为0*//* border-bottom: 0px solid blue;border-left: 0px solid green; *//*可以简写*//*只保留右边边框有颜色*/border-color: transparent red transparent transparent;/*样式都是solid*/border-style: solid;/*上边框宽度要大,右边框宽度稍小,其余边框为0*/border-width: 100px 50px 0 0;}.price {width: 160px;height: 24px;line-height: 24px;border: 1px solid red;margin: 100px auto;}.miaosha {position: relative;float: left;width: 90px;height: 100%;background-color: red;text-align: center;color: #fff;font-weight: 700;margin-right: 8px;}.miaosha i {position: absolute;right: 0;top: 0;width: 0;height: 0;border-color: transparent #fff transparent transparent;border-style: solid;border-width: 24px 10px 0 0;}.origin {font-size: 12px;color: gray;text-decoration: line-through;}</style>
</head><body><div class="box1"></div><div class="price"><span class="miaosha">¥1650<i></i></span><span class="origin">¥5650</span></div>
</body></html>

结果展示:
在这里插入图片描述
左上角的三角形是我们测试时写的,代码中有所以也展示在上面了。

8. CSS初始化

不同浏览器对有些标签的默认值不同,为了消除不同浏览器对HTML文本呈现的差异,照顾浏览器的兼容,我们需要对CSS初始化。(即重设浏览器样式),这里以京东CSS为例。
代码及其部分解释如下:

/* 把我们所有标签的内外边距清零 */
* {margin: 0;padding: 0
}/* em 和 i 斜体的文字不倾斜 */
em,
i {font-style: normal
}/* 去掉li 的小圆点 */
li {list-style: none
}img {/* border 0 照顾低版本浏览器 如果 图片外面包含了链接会有边框的问题 */border: 0;/* 取消图片底侧有空白缝隙的问题 */vertical-align: middle
}button {/* 当我们鼠标经过button 按钮的时候,鼠标变成小手 */cursor: pointer
}a {color: #666;text-decoration: none
}a:hover {color: #c81623
}button,
input {/* "\5B8B\4F53" 就是宋体的意思 这样浏览器兼容性比较好 */font-family: Microsoft YaHei, Heiti SC, tahoma, arial, Hiragino Sans GB, "\5B8B\4F53", sans-serif
}body {/* CSS3 抗锯齿形 让文字显示的更加清晰 */-webkit-font-smoothing: antialiased;background-color: #fff;font: 12px/1.5 Microsoft YaHei, Heiti SC, tahoma, arial, Hiragino Sans GB, "\5B8B\4F53", sans-serif;color: #666
}.hide,
.none {display: none
}/* 清除浮动 */
.clearfix:after {visibility: hidden;clear: both;display: block;content: ".";height: 0
}/* .clearfix {*zoom: 1
} *//*这里和之前一样目前的vscode中会报错*/

Unicode编码字体:
把中文字体的名称用相应的Unicode编码来代替,可以有效避免浏览器解释CSS代码出现乱码的问题。
比如:
黑体: \9ED1\4F53
宋体: \5B8B\4F53
微软雅黑:\5FAE\8F6F\96C5\9ED1

—————————————————————————————————————————
第七天知识点已讲解完毕,下面即将更新课程HTML和CSS3提高的内容哦(ง •_•)ง,有什么问题都可以在评论区进行讨论哦!

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com