有关文本CSS样式
文本溢出省略
<style>/* 单行文本溢出 */p {width: 100px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;}/* 多行文本溢出 */span {width: 100px;display: -webkit-box;/* 布局箱子 方向为垂直 */-webkit-box-orient: vertical;/* 线夹 */-webkit-line-clamp: 3;overflow: hidden;}</style><body><!-- 单行文本省略 --><p>你好shijie世界你好shijie世界你好shijie世界你好shijie世界你好shijie世界</p><span>你好世界你好世界你好世界你好世界你好世界你好世界你好世界你好世界你好世界你好世界</span></body>
文本换行问题
word-break:break-all: 只对英文起作用, 以字母作为换行依据word-wrap:break-word: 只对英文起作用, 以单词作为换行依据white-space:pre-wrap: 只对中文起作用, 强制换行white-space:nowrap: 强制不换行, 都起作用
<style>p {width: 200px;white-space: pre-wrap;}</style><p>ruguogaiwenbenkuangzhongdecishizifuzebujinxinghuanhangcaozuo</p>
文字的阴影text-shadow
- 参数介绍:x偏移量, y偏移量, 模糊程度, 颜色
文字之间的间距
text-indent表示段落的缩进距离,letter-spacing表示的是字与字之间的间距
文本竖向排列
/* // 单列展示时 */p {width: 25px;line-height: 18px;height: auto;font-size: 12px;padding: 8px 5px;word-wrap: break-word;/*英文的时候需要加上这句,自动换行*/}/* // 多列展示时 */span {height: 210px;line-height: 30px;text-align: justify;writing-mode: vertical-lr;writing-mode: tb-lr;/* //writing-mode: vertcal-rl; -- 从右向左//writing-mode: tb-rl; -- 从右向左 */}
文本渐变效果
-webkit-background-clip: text;-webkit-text-fill-color: transparent;background-image: linear-gradient(to right, #ec2239, #40a4e2, #ea96f5);
设置placeholder样式
- 兼容不同的浏览器的问题:-webkit-, -ms-, -o-, -moz-
input::-[兼容的内核名称]-input-placeholder
滚动条问题
ios页面滑动卡顿的问题
body,html {-webkit-overflow-scrolling: touch}
设置滚动条样式
/* 定义整个滑动条的宽度和高度 */body::-webkit-scrollbar {width: 5px;height: 20px;}/* 定义滑块的样式 */body::-webkit-scrollbar-thumb {border-radius: 10px;background-color: #000;}/* 定义滑块里面的轨道 */body::-webkit-scrollbar-track {box-shadow: inset 0 0 10px #ccc;border-radius: 10px;background-color: rgb(151, 234, 240);}
实现隐藏滚动条 同时又可以滚动
body::-webkit-scrollbar {display: none;/* Chrome Safari */}body {scrollbar-width: none;/* firefox */-ms-overflow-style: none;/* IE 10+ */overflow-x: hidden;overflow-y: auto;}
onerror处理图片异常
- 如果图片出现异常, 将新的图片地址赋给当前的img标签src属性并且将当前的onerror指令设为空, 以免进入死循环情况
<img src="" onerror="this.src='https://tva3.sinaimg.cn/large/0072Vf1pgy1foxloigdl2j31kw0w0kib.jpg';this.onerror=null" />
用户有关的事件
使得元素鼠标事件失效
button {pointer-events: none;cursor: default}
禁止用户选择页面中的内容
.text {-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;}
开启硬件加速GPU
transform: translateZ(0);
页面动画出现闪烁问题
/* 第一种 */-webkit-backface-visibility: hidden;backface-visibility: hidden;-webkit-perspective: 1000;perspective: 1000;/* 第二种 */-webkit-transform: translate3d(0, 0, 0);transform: translate3d(0, 0, 0);
字母大小写转换
p {text-transform: uppercase}// 将所有字母变成大写字母p {text-transform: lowercase}// 将所有字母变成小写字母p {text-transform: capitalize}// 首字母大写p {font-variant: small-caps}// 将字体变成小型的大写字母
解决vertical-align属性不生效
- 在使用vertical-align:middle实现垂直居中的时候, 经常会发现不生效的情况. 这里需要注意它生效需要满足的条件:
作用环境:父元素设置line-height. 需要和height一致. 或者将display属性设置为table-cell, 将块元素转化为单元格.
作用对象:子元素中的inline-block和inline元素.
