css样式小技巧

1、改变鼠标样式

把鼠标改成自己喜欢的小图片

*{cursor:url(https://blog-static.cnblogs.com/files/blogs/725648/cursora.ico),auto;}

2、鼠标选中样式

鼠标选中样式,背景颜色,文字颜色的修改

/* webkit, opera, IE9 */
::selection { background:#807dd4; color: #fff;}
/* mozilla firefox */
::-moz-selection { background:#807dd4; color: #fff; }

3、自定义页面滚动条

自定义页面滚动条样式,div什么都可以用,将html换成div的class名称即可

html::-webkit-scrollbar-thumb {
height: 40px;
border-radius: 16px;
background-color: #ccc;
}
html::-webkit-scrollbar {
width: 10px;
height: 10px;
border-radius: 2px;
}

4、CSS变量

通过样式表中任何位置的关键字重用

:root {
--main-color: #06c;
--accent-color: #999;
}
h1, h2, h3 {
color: var(--main-color);
}
footer span{
color: var(--accent-color);
}

5、解决ios滑动时无缓冲问题

-webkit-overflow-scrolling: touch;

6、强行换行css

有时候做页面,测试打一个很长很长的字符或者数字来,文字就会显示在页面外面,这时就需要一个强制换行

white-space:pre-wrap; /* css3.0 */
white-space:-moz-pre-wrap; /* Firefox */
white-space:-pre-wrap; /* Opera 4-6 */
white-space:-o-pre-wrap; /* Opera 7 */
word-wrap:break-word; /* Internet Explorer 5.5+ */

7、文本溢出显示省略号

width宽度,-webkit-line-clamp要显示几行,自行设置

width: 200px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3;

8、不能选中文本

user-select设置不能选中文本

-moz-user-select: none; -webkit-user-select: none; -ms-user-select: none; -khtml-user-select: none; user-select: none;

9、偏移自身50%

transform: translate(-50%,-50%);

10、苹果手机底部小横线

padding-bottom: calc(0 + constant(safe-area-inset-bottom));
padding-bottom: calc(0 + env(safe-area-inset-bottom));

11、动画效果

transition: all 0.15s linear;

12、投影

box-shadow: 0 6rpx 22rpx rgb(0 0 0 / 25%);

13、文字描边

//
// 这里使用了外描边文字效果
//
.plan-bg2 {
font-family: Heavy;
font-size: 30px;
font-weight: 900;
/* 设置描边宽度及颜色 /
text-stroke: 2px #2173FF;
/ 兼容Webkit(Chrome/Safari)内核浏览器的写法 /
-webkit-text-stroke: 2px #2173FF;
}
/ 通过属性选择器结合伪元素before 实现文字外描边效果 /
[data-content]::before {
/ attr()是用来获取被选中元素的某属性值,并且在样式文件中使用 /
content: attr(data-content);
position: absolute;
/ 实现元素外描边的关键 /
-webkit-text-stroke: 0;
/ 文本颜色 */
color: #fff;
}

14、缩放

scale: 1.2;

15、横向滚动

父:
white-space: nowrap;
overflow-x: auto;
子:{
display: inline-flex;
align-items: center;
justify-content: center;
}

16、段落缩进前两个字符

text-indent: 28px;

17、翻转

transform:rotateX(180deg);

18、文字渐变色

background-image: linear-gradient(to right, #ce25c0, #d6e56e, #ee2cb3, #deae42);
-webkit-background-clip: text;
color: transparent;
display: inline-block;
animation: colorflashing-444ad1fa 1.5s ease-in-out infinite;
-webkit-animation: colorflashing-444ad1fa 1.5s ease-in-out infinite;

19、渐变色

background: linear-gradient(90deg, #ffc046, #ff7d04);
background-image: linear-gradient(270deg, #4940AC 0%, #00A38E 100%);

20、渐变色 背景图共存

background: url('https://szy-mms.oss-cn-beijing.aliyuncs.com/assets/expert-images/static/images/bg/capital-bg.png')
no-repeat center / 100%,
linear-gradient(90deg, #ffc046, #ff7d04);

后期遇到比较不错的,会不断的完善

posted @   蓦然JL  阅读(71)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
  1. 1 唯一 G.E.M.邓紫棋
  2. 2 他只是经过 白敬亭 魏大勋
  3. 3 Uptown Funk Mark Ronson / Bruno Mars
  4. 4 在你的身边 盛哲
  5. 5 Edge of My Life Manafest
  6. 6 凄美地 郭顶
  7. 7 Wonderful Tonight Boyce Avenue
  8. 8 心如止水 Ice Paper
  9. 9 Sugar Maroon 5
  10. 10 静谧时光 JIAxNING
  11. 11 Right Now (Na Na Na) Aamir
  12. 12 Dangerously Charlie Puth
  13. 13 Someone You Loved Madilyn Paige
  14. 14 Shape of My Heart Boyce Avenue
  15. 15 We Can't Stop Boyce Avenue / Bea Miller
  16. 16 Perfect Boyce Avenue
  17. 17 Love Me Like You Do Boyce Avenue
  18. 18 Thank You Boyce Avenue
  19. 19 Don’t Wanna Know Boyce Avenue / Sarah Hyland
他只是经过 - 白敬亭 魏大勋
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

Not available

访问主页
关注我
关注微博
私信我
返回顶部
点击右上角即可分享
微信分享提示

目录导航