2023年6月20日发(作者:)

常⽤CSS笔记常⽤CSS笔记1、⽂字超出部分显⽰省略号单⾏⽂本的溢出显⽰省略号(⼀定要有宽度) p{ width:200rpx; overflow: hidden; text-overflow:ellipsis; white-space: nowrap; }多⾏⽂本溢出显⽰省略号p { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }2、中英⽂⾃动换⾏word-break:break-all;只对英⽂起作⽤,以字母作为换⾏依据word-wrap:break-word; 只对英⽂起作⽤,以单词作为换⾏依据white-space:pre-wrap; 只对中⽂起作⽤,强制换⾏white-space:nowrap; 强制不换⾏,都起作⽤p{ word-wrap: break-word; white-space: normal; word-break: break-all;}//不换⾏.wrap { white-space:nowrap;}//⾃动换⾏.wrap { word-wrap: break-word; word-break: normal;}//强制换⾏.wrap { word-break:break-all;}3、⽂字阴影text-shadow 为⽹页字体添加阴影,通过对text-shadow属性设置相关的属性值。属性与值的说明如下:text-shadow: [X-offset,Y-offset,Blur,Color];X-offset:指阴影居于字体⽔平偏移的位置。Y-offset:指阴影居于字体垂直偏移的位置。Blur:指阴影的模糊值。color:指阴影的颜⾊;h1{text-shadow: 5px 5px 5px #FF0000;}4、设置placeholder的字体样式input::-webkit-input-placeholder { /* Chrome/Opera/Safari */ color: red;}input::-moz-placeholder { /* Firefox 19+ */ color: red;}input:-ms-input-placeholder { /* IE 10+ */ color: red;}input:-moz-placeholder { /* Firefox 18- */ color: red;}5、不固定⾼宽 div 垂直居中的⽅法⽅法⼀:伪元素和 inline-block / vertical-align(兼容 IE8).box-wrap:before { content: ''; display: inline-block; height: 100%; vertical-align: middle; margin-right: -0.25em; //微调整空格}.box { display: inline-block; vertical-align: middle;}⽅法⼆:flex(不兼容 ie8 以下).box-wrap { height: 300px; justify-content:center; align-items:center; display:flex; background-color:#666; }⽅法三:transform(不兼容 ie8 以下) .box-wrap { width:100%; height:300px; background:rgba(0,0,0,0.7); position:relative;}.box{ position:absolute; left:50%; top:50%; transform:translateX(-50%) translateY(-50%); -webkit-transform:translateX(-50%) translateY(-50%);}⽅法四:设置 margin:auto(该⽅法得严格意义上的⾮固定宽⾼,⽽是 50%的⽗级的宽⾼。).box-wrap { position: relative; width:100%; height:300px; background-color:#f00;}.box-content{ position: absolute; top:0; left:0; bottom:0; right:0; width:50%; height:50%; margin:auto; background-color:#ff0;}6、解决IOS页⾯滑动卡顿body,html{ -webkit-overflow-scrolling: touch;}7、设置滚动条样式.test::-webkit-scrollbar{ /*滚动条整体样式*/ width : 10px; /*⾼宽分别对应横竖滚动条的尺⼨*/ height: 1px;}.test::-webkit-scrollbar-thumb { /*滚动条⾥⾯⼩⽅块*/ border-radius : 10px; background-color: skyblue; background-image: -webkit-linear-gradient( 45deg, rgba(255, 255, 255, 0.2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.2) 75%, transparent 75%, transparent );}.test::-webkit-scrollbar-track { /*滚动条⾥⾯轨道*/ box-shadow : inset 0 0 5px rgba(0, 0, 0, 0.2); background : #ededed; border-radius: 10px;}8、实现隐藏滚动条同时⼜可以滚动.demo::-webkit-scrollbar { display: none; /* Chrome Safari */}.demo { scrollbar-width: none; /* firefox */ -ms-overflow-style: none; /* IE 10+ */ overflow-x: hidden; overflow-y: auto;}9、css 绘制三⾓形div { width: 0; height: 0; border-width: 0 40px 40px; border-style: solid; border-color: transparent transparent red;}效果如下:图⽚实现带边框的三⾓形:

#blue { position:relative; width: 0; height: 0; border-width: 0 40px 40px; border-style: solid; border-color: transparent transparent blue;}#blue:after { content: ""; position: absolute; top: 1px; left: -38px; border-width: 0 38px 38px; border-style: solid; border-color: transparent transparent yellow;}效果如下:图⽚注: 如果想绘制右直⾓三⾓,则将左 border 设置为 0;如果想绘制左直⾓三⾓,将右 border 设置为 0 即可(其它情况同理)。10、Table表格边框合并table,tr,td{ border: 1px solid #666;}table{ border-collapse: collapse;}11、css 选取第 n 个标签元素first-child first-child 表⽰选择列表中的第⼀个标签。last-child last-child 表⽰选择列表中的最后⼀个标签nth-child(3) 表⽰选择列表中的第 3 个标签nth-child(2n) 这个表⽰选择列表中的偶数标签nth-child(2n-1) 这个表⽰选择列表中的奇数标签nth-child(n+3) 这个表⽰选择列表中的标签从第 3 个开始到最后。nth-child(-n+3) 这个表⽰选择列表中的标签从 0 到 3,即⼩于 3 的标签。nth-last-child(3) 这个表⽰选择列表中的倒数第 3 个标签。使⽤⽅法:li:first-child{}12、移动端软键盘变为搜索⽅式默认情况下软键盘上该键位为前往或者确认等⽂字,要使其变为搜索⽂字,需要在 input 上加上 type 声明:
需要⼀个 form 标签套起来,并且设置 action 属性,这样写完之后输⼊法的右下⾓就会⾃动变成搜索,同时,使⽤了 search 类型后,搜索框上会默认⾃带删除按钮。13、onerror 处理图⽚异常使⽤ onerror 异常处理时,若 onerror 的图⽚也出现问题,则图⽚显⽰会陷⼊死循环,所以要在赋值异常图⽚之后,将地址置空14、背景图⽚的⼤⼩.bg-img{ background:url(../img/find_pw_on_) no-repeat center center !important; background-size: 27px auto !important; /*background-size: 100% 100%;*/ /*background-size: 50px 100px*/}15、⽂字之间的间距单词text-indent抬头距离,letter-spacing字与字间距p{ text-indent:10px;//单词抬头距离 letter-spacing:10px;//间距}16、元素占满整个屏幕heigth如果使⽤100%,会根据⽗级的⾼度来决定,所以使⽤100vh单位。.dom{ width:100%; height:100vh;}17、CSS实现⽂本两端对齐.wrap { text-align: justify; text-justify: distribute-all-lines; //ie6-8 text-align-last: justify; //⼀个块或⾏的最后⼀⾏对齐⽅式 -moz-text-align-last: justify; -webkit-text-align-last: justify;}18、实现⽂字竖向排版// 单列展⽰时.wrap { width: 25px; line-height: 18px; height: auto; font-size: 12px; padding: 8px 5px; word-wrap: break-word;/*英⽂的时候需要加上这句,⾃动换⾏*/

}// 多列展⽰时.wrap { height: 210px; line-height: 30px; text-align: justify; writing-mode: vertical-lr; //从左向右

writing-mode: tb-lr; //IE从左向右 //writing-mode: vertical-rl; -- 从右向左 //writing-mode: tb-rl; -- 从右向左}19、使元素⿏标事件失效.wrap { // 如果按tab能选中该元素,如button,然后按回车还是能执⾏对应的事件,如click。 pointer-events: none; cursor: default;}20、禁⽌⽤户选择.wrap { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;}21、使⽤硬件加速在浏览器中⽤css开启硬件加速,使GPU (Graphics Processing Unit) 发挥功能,从⽽提升性能。硬件加速在移动端尤其有⽤,因为它可以有效的减少资源的利⽤。⽬前主流浏览器会检测到页⾯中某个DOM元素应⽤了某些CSS规则时就会开启,最显著的特征的元素的3D变换。如果不使⽤3D变形,我们可以通过下⾯⽅式来开启:.wrap { transform: translateZ(0);}22、页⾯动画出现闪烁问题在 Chrome and Safari中,当我们使⽤CSS transforms 或者 animations时可能会有页⾯闪烁的效果,下⾯的代码可以修复此情况:.cube { -webkit-backface-visibility: hidden; backface-visibility: hidden;

-webkit-perspective: 1000; perspective: 1000; /* Other transform properties here */}在webkit内核的浏览器中,另⼀个⾏之有效的⽅法是.cube { -webkit-transform: translate3d(0, 0, 0); transform: translate3d(0, 0, 0); /* Other transform properties here */}23、字母⼤⼩写转换p {text-transform: uppercase} // 将所有字母变成⼤写字母p {text-transform: lowercase} // 将所有字母变成⼩写字母p {text-transform: capitalize} // ⾸字母⼤写p {font-variant: small-caps} // 将字体变成⼩型的⼤写字母24、将⼀个容器设为透明.wrap {

filter:alpha(opacity=50);

-moz-opacity:0.5;

-khtml-opacity: 0.5;

opacity: 0.5;

}25、消除transition闪屏.wrap { -webkit-transform-style: preserve-3d; -webkit-backface-visibility: hidden; -webkit-perspective: 1000;}26、识别字符串⾥的 'n' 并换⾏⼀般在富⽂本中返回换⾏符不是的标签,⽽且n。不使⽤正则转换的情况下,可通过下⾯样式实现换⾏。body { white-space: pre-line;}27、移除a标签被点链接的边框a { outline: none;//或者outline: 0 text-decoration:none; //取消默认下划线}28、CSS显⽰链接之后的URL有课前端⽹29、select内容居中显⽰、下拉内容右对齐select{ text-align: center; text-align-last: center;}select option { direction: rtl;}30、修改input输⼊框中光标的颜⾊不改变字体的颜⾊input{ color: #fff; caret-color: red;}31、⼦元素固定宽度 ⽗元素宽度被撑开// ⽗元素下的⼦元素是⾏内元素.wrap { white-space: nowrap;}// 若⽗元素下的⼦元素是块级元素.wrap { white-space: nowrap; // ⼦元素不被换⾏ display: inline-block;}32、让div⾥的图⽚和⽂字同时上下居中这⾥不使⽤flex布局的情况。通过 { height: 100, line-height: 100}img { vertival-align:middle}// vertical-align css的属性vertical-align⽤来指定⾏内元素(inline)或表格单元格(table-cell)元素的垂直对齐⽅式。只对⾏内元素、表格单元格元素⽣效,不能⽤它垂直对齐块// vertical-align:baseline/top/middle/bottom/sub/text-top;33、实现宽⾼等⽐例⾃适应矩形.scale { width: 100%; padding-bottom: 56.25%; height: 0; position: relative;

}.item { position: absolute;

width: 100%; height: 100%; background-color: 499e56;}

这⾥是所有⼦元素的容器
34、transfrom的rotate属性在span标签下失效span { display: inline-block}35、CSS加载动画主要是通过css旋转动画的实现:.dom{ -webkit-animation:circle 1s infinite linear;}@keyframes circle{ 0%{ transform: rotate(0deg); } 100%{ transform: rotate(360deg); }}实现如下效果:
36、⽂字渐变效果实现
fly63前端⽹,⼀个免费学习前端知识的⽹站
37、好看的边框阴影
38、好看的背景渐变
39、实现⽴体字的效果
有课前端⽹-web前端技术学习平台
40、全屏背景图⽚的实现.swper{ background-image: url(./img/); width:100%; height:100%;//⽗级⾼不为100%请使⽤100vh zoom: 1; background-color: #fff; background-repeat: no-repeat; background-size: cover; -webkit-background-size: cover; -o-background-size: cover; background-position: center 0;}41、实现⽂字描边的2种⽅法⽅式⼀:.stroke { -webkit-text-stroke: 1px greenyellow; text-stroke: 1px greenyellow;}⽅式⼆:.stroke { text-shadow:#000 1px 0 0,#000 0 1px 0,#000 -1px 0 0,#000 0 -1px 0; -webkit-text-shadow:#000 1px 0 0,#000 0 1px 0,#000 -1px 0 0,#000 0 -1px 0; -moz-text-shadow:#000 1px 0 0,#000 0 1px 0,#000 -1px 0 0,#000 0 -1px 0; *filter: Glow(color=#000, strength=1);}42、元素透明度的实现.dom{ opacity:0.4; filter:alpha(opacity=40); /* IE8 及其更早版本 */}使⽤rgba()设置颜⾊透明度。.demo{ background:rgba(255,0,0,1);}说明:RGBA 是代表Red(红⾊) Green(绿⾊) Blue(蓝⾊)和 Alpha(不透明度)三个单词的缩写。43、解决1px边框变粗问题.dom{ height: 1px; background: #dbdbdb; transform:scaleY(0.5);}Ps:出现1px变粗的原因,⽐如在2倍屏时1px的像素实际对应2个物理像素。44、CSS不同单位的运算css⾃⼰也能够进⾏简单的运算,主要是⽤到了calc这个函数。实现不同单位的加减运算:.div{

width: calc(100% - 50px);

}45、CSS实现⽂字模糊效果.vague_text{ color: transparent;

text-shadow: #111 0 0 5px;}46、通过滤镜让图标变灰⼀张彩⾊的图⽚就能实现⿏标移⼊变彩⾊,移出变灰的效果。47、图⽚⾃适应object-fit当图⽚⽐例不固定时,想要让图⽚⾃适应,⼀般都会⽤background-size:cover/contain,但是这个只适⽤于背景图。css3中可使⽤object-fit属性来解决图⽚被拉伸或是被缩放的问题。使⽤的提前条件:图⽚的⽗级容器要有宽⾼。img{ width: 100%; height: 100%; object-fit: cover;}fill: 默认值。内容拉伸填满整个content box, 不保证保持原有的⽐例。contain: 保持原有尺⼨⽐例。长度和⾼度中长的那条边跟容器⼤⼩⼀致,短的那条等⽐缩放,可能会有留⽩。cover: 保持原有尺⼨⽐例。宽度和⾼度中短的那条边跟容器⼤⼩⼀致,长的那条等⽐缩放。可能会有部分区域不可见。(常⽤)none: 保持原有尺⼨⽐例。同时保持替换内容原始尺⼨⼤⼩。scale-down:保持原有尺⼨⽐例,如果容器尺⼨⼤于图⽚内容尺⼨,保持图⽚的原有尺⼨,不会放⼤失真;容器尺⼨⼩于图⽚内容尺⼨,⽤法跟contain⼀样。48、⾏内标签元素出现间隙问题⽅式⼀:⽗级font-size设置为{ font-size:0;}⽅式⼆:⽗元素上设置word-spacing的值为合适的负值.father{ word-spacing:-2px}其它⽅案:1将⾏内元素写为1⾏(影响阅读);2使⽤浮动样式(会影响布局)。49、解决vertical-align属性不⽣效在使⽤vertical-align:middle实现垂直居中的时候,经常会发现不⽣效的情况。这⾥需要注意它⽣效需要满⾜的条件:作⽤环境:⽗元素设置line-height。需要和height⼀致。或者将display属性设置为table-cell,将块元素转化为单元格。作⽤对象:⼦元素中的inline-block和inline元素。

内部⽂字
PS:vertical-align不可继承,必须对⼦元素单独设置。同时需要注意的是line-height的⾼度基于font-size(即字体的⾼度),如果⽂字要转⾏会出现异常。

2023年6月20日发(作者:)

常⽤CSS笔记常⽤CSS笔记1、⽂字超出部分显⽰省略号单⾏⽂本的溢出显⽰省略号(⼀定要有宽度) p{ width:200rpx; overflow: hidden; text-overflow:ellipsis; white-space: nowrap; }多⾏⽂本溢出显⽰省略号p { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }2、中英⽂⾃动换⾏word-break:break-all;只对英⽂起作⽤,以字母作为换⾏依据word-wrap:break-word; 只对英⽂起作⽤,以单词作为换⾏依据white-space:pre-wrap; 只对中⽂起作⽤,强制换⾏white-space:nowrap; 强制不换⾏,都起作⽤p{ word-wrap: break-word; white-space: normal; word-break: break-all;}//不换⾏.wrap { white-space:nowrap;}//⾃动换⾏.wrap { word-wrap: break-word; word-break: normal;}//强制换⾏.wrap { word-break:break-all;}3、⽂字阴影text-shadow 为⽹页字体添加阴影,通过对text-shadow属性设置相关的属性值。属性与值的说明如下:text-shadow: [X-offset,Y-offset,Blur,Color];X-offset:指阴影居于字体⽔平偏移的位置。Y-offset:指阴影居于字体垂直偏移的位置。Blur:指阴影的模糊值。color:指阴影的颜⾊;h1{text-shadow: 5px 5px 5px #FF0000;}4、设置placeholder的字体样式input::-webkit-input-placeholder { /* Chrome/Opera/Safari */ color: red;}input::-moz-placeholder { /* Firefox 19+ */ color: red;}input:-ms-input-placeholder { /* IE 10+ */ color: red;}input:-moz-placeholder { /* Firefox 18- */ color: red;}5、不固定⾼宽 div 垂直居中的⽅法⽅法⼀:伪元素和 inline-block / vertical-align(兼容 IE8).box-wrap:before { content: ''; display: inline-block; height: 100%; vertical-align: middle; margin-right: -0.25em; //微调整空格}.box { display: inline-block; vertical-align: middle;}⽅法⼆:flex(不兼容 ie8 以下).box-wrap { height: 300px; justify-content:center; align-items:center; display:flex; background-color:#666; }⽅法三:transform(不兼容 ie8 以下) .box-wrap { width:100%; height:300px; background:rgba(0,0,0,0.7); position:relative;}.box{ position:absolute; left:50%; top:50%; transform:translateX(-50%) translateY(-50%); -webkit-transform:translateX(-50%) translateY(-50%);}⽅法四:设置 margin:auto(该⽅法得严格意义上的⾮固定宽⾼,⽽是 50%的⽗级的宽⾼。).box-wrap { position: relative; width:100%; height:300px; background-color:#f00;}.box-content{ position: absolute; top:0; left:0; bottom:0; right:0; width:50%; height:50%; margin:auto; background-color:#ff0;}6、解决IOS页⾯滑动卡顿body,html{ -webkit-overflow-scrolling: touch;}7、设置滚动条样式.test::-webkit-scrollbar{ /*滚动条整体样式*/ width : 10px; /*⾼宽分别对应横竖滚动条的尺⼨*/ height: 1px;}.test::-webkit-scrollbar-thumb { /*滚动条⾥⾯⼩⽅块*/ border-radius : 10px; background-color: skyblue; background-image: -webkit-linear-gradient( 45deg, rgba(255, 255, 255, 0.2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.2) 75%, transparent 75%, transparent );}.test::-webkit-scrollbar-track { /*滚动条⾥⾯轨道*/ box-shadow : inset 0 0 5px rgba(0, 0, 0, 0.2); background : #ededed; border-radius: 10px;}8、实现隐藏滚动条同时⼜可以滚动.demo::-webkit-scrollbar { display: none; /* Chrome Safari */}.demo { scrollbar-width: none; /* firefox */ -ms-overflow-style: none; /* IE 10+ */ overflow-x: hidden; overflow-y: auto;}9、css 绘制三⾓形div { width: 0; height: 0; border-width: 0 40px 40px; border-style: solid; border-color: transparent transparent red;}效果如下:图⽚实现带边框的三⾓形:

#blue { position:relative; width: 0; height: 0; border-width: 0 40px 40px; border-style: solid; border-color: transparent transparent blue;}#blue:after { content: ""; position: absolute; top: 1px; left: -38px; border-width: 0 38px 38px; border-style: solid; border-color: transparent transparent yellow;}效果如下:图⽚注: 如果想绘制右直⾓三⾓,则将左 border 设置为 0;如果想绘制左直⾓三⾓,将右 border 设置为 0 即可(其它情况同理)。10、Table表格边框合并table,tr,td{ border: 1px solid #666;}table{ border-collapse: collapse;}11、css 选取第 n 个标签元素first-child first-child 表⽰选择列表中的第⼀个标签。last-child last-child 表⽰选择列表中的最后⼀个标签nth-child(3) 表⽰选择列表中的第 3 个标签nth-child(2n) 这个表⽰选择列表中的偶数标签nth-child(2n-1) 这个表⽰选择列表中的奇数标签nth-child(n+3) 这个表⽰选择列表中的标签从第 3 个开始到最后。nth-child(-n+3) 这个表⽰选择列表中的标签从 0 到 3,即⼩于 3 的标签。nth-last-child(3) 这个表⽰选择列表中的倒数第 3 个标签。使⽤⽅法:li:first-child{}12、移动端软键盘变为搜索⽅式默认情况下软键盘上该键位为前往或者确认等⽂字,要使其变为搜索⽂字,需要在 input 上加上 type 声明:
需要⼀个 form 标签套起来,并且设置 action 属性,这样写完之后输⼊法的右下⾓就会⾃动变成搜索,同时,使⽤了 search 类型后,搜索框上会默认⾃带删除按钮。13、onerror 处理图⽚异常使⽤ onerror 异常处理时,若 onerror 的图⽚也出现问题,则图⽚显⽰会陷⼊死循环,所以要在赋值异常图⽚之后,将地址置空14、背景图⽚的⼤⼩.bg-img{ background:url(../img/find_pw_on_) no-repeat center center !important; background-size: 27px auto !important; /*background-size: 100% 100%;*/ /*background-size: 50px 100px*/}15、⽂字之间的间距单词text-indent抬头距离,letter-spacing字与字间距p{ text-indent:10px;//单词抬头距离 letter-spacing:10px;//间距}16、元素占满整个屏幕heigth如果使⽤100%,会根据⽗级的⾼度来决定,所以使⽤100vh单位。.dom{ width:100%; height:100vh;}17、CSS实现⽂本两端对齐.wrap { text-align: justify; text-justify: distribute-all-lines; //ie6-8 text-align-last: justify; //⼀个块或⾏的最后⼀⾏对齐⽅式 -moz-text-align-last: justify; -webkit-text-align-last: justify;}18、实现⽂字竖向排版// 单列展⽰时.wrap { width: 25px; line-height: 18px; height: auto; font-size: 12px; padding: 8px 5px; word-wrap: break-word;/*英⽂的时候需要加上这句,⾃动换⾏*/

}// 多列展⽰时.wrap { height: 210px; line-height: 30px; text-align: justify; writing-mode: vertical-lr; //从左向右

writing-mode: tb-lr; //IE从左向右 //writing-mode: vertical-rl; -- 从右向左 //writing-mode: tb-rl; -- 从右向左}19、使元素⿏标事件失效.wrap { // 如果按tab能选中该元素,如button,然后按回车还是能执⾏对应的事件,如click。 pointer-events: none; cursor: default;}20、禁⽌⽤户选择.wrap { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;}21、使⽤硬件加速在浏览器中⽤css开启硬件加速,使GPU (Graphics Processing Unit) 发挥功能,从⽽提升性能。硬件加速在移动端尤其有⽤,因为它可以有效的减少资源的利⽤。⽬前主流浏览器会检测到页⾯中某个DOM元素应⽤了某些CSS规则时就会开启,最显著的特征的元素的3D变换。如果不使⽤3D变形,我们可以通过下⾯⽅式来开启:.wrap { transform: translateZ(0);}22、页⾯动画出现闪烁问题在 Chrome and Safari中,当我们使⽤CSS transforms 或者 animations时可能会有页⾯闪烁的效果,下⾯的代码可以修复此情况:.cube { -webkit-backface-visibility: hidden; backface-visibility: hidden;

-webkit-perspective: 1000; perspective: 1000; /* Other transform properties here */}在webkit内核的浏览器中,另⼀个⾏之有效的⽅法是.cube { -webkit-transform: translate3d(0, 0, 0); transform: translate3d(0, 0, 0); /* Other transform properties here */}23、字母⼤⼩写转换p {text-transform: uppercase} // 将所有字母变成⼤写字母p {text-transform: lowercase} // 将所有字母变成⼩写字母p {text-transform: capitalize} // ⾸字母⼤写p {font-variant: small-caps} // 将字体变成⼩型的⼤写字母24、将⼀个容器设为透明.wrap {

filter:alpha(opacity=50);

-moz-opacity:0.5;

-khtml-opacity: 0.5;

opacity: 0.5;

}25、消除transition闪屏.wrap { -webkit-transform-style: preserve-3d; -webkit-backface-visibility: hidden; -webkit-perspective: 1000;}26、识别字符串⾥的 'n' 并换⾏⼀般在富⽂本中返回换⾏符不是的标签,⽽且n。不使⽤正则转换的情况下,可通过下⾯样式实现换⾏。body { white-space: pre-line;}27、移除a标签被点链接的边框a { outline: none;//或者outline: 0 text-decoration:none; //取消默认下划线}28、CSS显⽰链接之后的URL有课前端⽹29、select内容居中显⽰、下拉内容右对齐select{ text-align: center; text-align-last: center;}select option { direction: rtl;}30、修改input输⼊框中光标的颜⾊不改变字体的颜⾊input{ color: #fff; caret-color: red;}31、⼦元素固定宽度 ⽗元素宽度被撑开// ⽗元素下的⼦元素是⾏内元素.wrap { white-space: nowrap;}// 若⽗元素下的⼦元素是块级元素.wrap { white-space: nowrap; // ⼦元素不被换⾏ display: inline-block;}32、让div⾥的图⽚和⽂字同时上下居中这⾥不使⽤flex布局的情况。通过 { height: 100, line-height: 100}img { vertival-align:middle}// vertical-align css的属性vertical-align⽤来指定⾏内元素(inline)或表格单元格(table-cell)元素的垂直对齐⽅式。只对⾏内元素、表格单元格元素⽣效,不能⽤它垂直对齐块// vertical-align:baseline/top/middle/bottom/sub/text-top;33、实现宽⾼等⽐例⾃适应矩形.scale { width: 100%; padding-bottom: 56.25%; height: 0; position: relative;

}.item { position: absolute;

width: 100%; height: 100%; background-color: 499e56;}

这⾥是所有⼦元素的容器
34、transfrom的rotate属性在span标签下失效span { display: inline-block}35、CSS加载动画主要是通过css旋转动画的实现:.dom{ -webkit-animation:circle 1s infinite linear;}@keyframes circle{ 0%{ transform: rotate(0deg); } 100%{ transform: rotate(360deg); }}实现如下效果:
36、⽂字渐变效果实现
fly63前端⽹,⼀个免费学习前端知识的⽹站
37、好看的边框阴影
38、好看的背景渐变
39、实现⽴体字的效果
有课前端⽹-web前端技术学习平台
40、全屏背景图⽚的实现.swper{ background-image: url(./img/); width:100%; height:100%;//⽗级⾼不为100%请使⽤100vh zoom: 1; background-color: #fff; background-repeat: no-repeat; background-size: cover; -webkit-background-size: cover; -o-background-size: cover; background-position: center 0;}41、实现⽂字描边的2种⽅法⽅式⼀:.stroke { -webkit-text-stroke: 1px greenyellow; text-stroke: 1px greenyellow;}⽅式⼆:.stroke { text-shadow:#000 1px 0 0,#000 0 1px 0,#000 -1px 0 0,#000 0 -1px 0; -webkit-text-shadow:#000 1px 0 0,#000 0 1px 0,#000 -1px 0 0,#000 0 -1px 0; -moz-text-shadow:#000 1px 0 0,#000 0 1px 0,#000 -1px 0 0,#000 0 -1px 0; *filter: Glow(color=#000, strength=1);}42、元素透明度的实现.dom{ opacity:0.4; filter:alpha(opacity=40); /* IE8 及其更早版本 */}使⽤rgba()设置颜⾊透明度。.demo{ background:rgba(255,0,0,1);}说明:RGBA 是代表Red(红⾊) Green(绿⾊) Blue(蓝⾊)和 Alpha(不透明度)三个单词的缩写。43、解决1px边框变粗问题.dom{ height: 1px; background: #dbdbdb; transform:scaleY(0.5);}Ps:出现1px变粗的原因,⽐如在2倍屏时1px的像素实际对应2个物理像素。44、CSS不同单位的运算css⾃⼰也能够进⾏简单的运算,主要是⽤到了calc这个函数。实现不同单位的加减运算:.div{

width: calc(100% - 50px);

}45、CSS实现⽂字模糊效果.vague_text{ color: transparent;

text-shadow: #111 0 0 5px;}46、通过滤镜让图标变灰⼀张彩⾊的图⽚就能实现⿏标移⼊变彩⾊,移出变灰的效果。47、图⽚⾃适应object-fit当图⽚⽐例不固定时,想要让图⽚⾃适应,⼀般都会⽤background-size:cover/contain,但是这个只适⽤于背景图。css3中可使⽤object-fit属性来解决图⽚被拉伸或是被缩放的问题。使⽤的提前条件:图⽚的⽗级容器要有宽⾼。img{ width: 100%; height: 100%; object-fit: cover;}fill: 默认值。内容拉伸填满整个content box, 不保证保持原有的⽐例。contain: 保持原有尺⼨⽐例。长度和⾼度中长的那条边跟容器⼤⼩⼀致,短的那条等⽐缩放,可能会有留⽩。cover: 保持原有尺⼨⽐例。宽度和⾼度中短的那条边跟容器⼤⼩⼀致,长的那条等⽐缩放。可能会有部分区域不可见。(常⽤)none: 保持原有尺⼨⽐例。同时保持替换内容原始尺⼨⼤⼩。scale-down:保持原有尺⼨⽐例,如果容器尺⼨⼤于图⽚内容尺⼨,保持图⽚的原有尺⼨,不会放⼤失真;容器尺⼨⼩于图⽚内容尺⼨,⽤法跟contain⼀样。48、⾏内标签元素出现间隙问题⽅式⼀:⽗级font-size设置为{ font-size:0;}⽅式⼆:⽗元素上设置word-spacing的值为合适的负值.father{ word-spacing:-2px}其它⽅案:1将⾏内元素写为1⾏(影响阅读);2使⽤浮动样式(会影响布局)。49、解决vertical-align属性不⽣效在使⽤vertical-align:middle实现垂直居中的时候,经常会发现不⽣效的情况。这⾥需要注意它⽣效需要满⾜的条件:作⽤环境:⽗元素设置line-height。需要和height⼀致。或者将display属性设置为table-cell,将块元素转化为单元格。作⽤对象:⼦元素中的inline-block和inline元素。

内部⽂字
PS:vertical-align不可继承,必须对⼦元素单独设置。同时需要注意的是line-height的⾼度基于font-size(即字体的⾼度),如果⽂字要转⾏会出现异常。