1.CSS linear-gradient() 背景渐变色函数:
/* 从上到下,蓝色渐变到红色 */
linear-gradient(blue, red);
/* 渐变轴为45度,从蓝色渐变到红色 */
linear-gradient(45deg, blue, red);
/* 从右下到左上、从蓝色渐变到红色 */
linear-gradient(to left top, blue, red);
/* 从下到上,从蓝色开始渐变、到高度40%位置是绿色渐变开始、最后以红色结束 */
linear-gradient(0deg, blue, green 40%, red);
/* 春秋权益中心、积分选座使用:*/
background: linear-gradient(to right, #d7f4df, #deedf8);
PC端需要兼容其他浏览器:
background: #d91915; /* Old browsers */
background: -webkit-linear-gradient(left, #d91915 ,#d00e31); /* Chrome10-25,Safari5.1-6 */
background: -moz-linear-gradient(right, #d91915, #d00e31); /* FF3.6-15 */
background: -ms-linear-gradient(right, #d91915, #d00e31); /* FF3.6-15 */
background: -o-linear-gradient(right, #d91915, #d00e31); /* FF3.6-15 */
background: linear-gradient(to right, #d91915,#d00e31); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#d91915', endColorstr='#d00e31',GradientType=1 ); /* IE6-9 */
M积分选座兼容写法:
background: -webkit-linear-gradient(left,rgba(230,230,230,0.6),rgba(255,255,255,0)); /* Chrome10-25,Safari5.1-6 */
background: -moz-linear-gradient(right, rgba(230,230,230,0.6),rgba(255,255,255,0)); /* FF3.6-15 */
background: -ms-linear-gradient(right, rgba(230,230,230,0.6),rgba(255,255,255,0)); /* FF3.6-15 */
background: -o-linear-gradient(right,rgba(230,230,230,0.6),rgba(255,255,255,0); /* FF3.6-15 */
background: linear-gradient(to right, rgba(230,230,230,0.6),rgba(255,255,255,0); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+
2.纯CSS 写一个三角形:
width: 0;
height: 0;
border-top: 50px solid transparent; /*这行去掉也行*/
border-bottom: 50px solid yellow;
border-right: 50px solid transparent;
border-left: 50px solid transparent;
3.纯CSS修改input复选框样式:
<input type="checkbox" name="btn1" id="btn1"/><label for="btn1">按钮1</label>
注意:input里面一定要加position:relative。不然选中时对号没有效果。
input[type="checkbox"]{
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
outline: none;
width:20px;
height:20px;
display: inner-block;
text-align: center;
vertical-align:middle;
line-height: 20px;
position: relative;
}
input[type="checkbox"]::before{
content:"";
position: absolute;
top:0:
left: 0;
background: #fff;
width:100%;
height:100%;
border: 1px solid #d9d9d9;
}
input[type=checkbox]:checked::before{
content: "\2713";
position: absolute;
top:0:
left: 0;
background: #fff;
width: 100%;
border: 1px solid #e50232;
color: #e50232;
font-size: 20px;
font-weight: 700;
}
4.scss ,px 自动转换为 rem:
<style lang="scss" scoped>
@function pxToRem($px) {
@return ($px/75)*1rem;
}
</style>
5.弹性布局盒子flex水平和垂直居中:
display: flex / inner-flex;
algin-item: center: //垂直居中
justify-content: center: //水平居中
6.修改 select标签默认样式:
隐藏默认下拉箭头,通过伪元素设置自定义下拉箭头
/*这个设置不支持IE*/ select {
border: 1px solid #CCCCCC ;
height: 27px;
width:116px;
-webkit-border-radius: 2px;
-moz-appearance: none;
-webkit-appearance: none;
padding-right:26px;
padding-left:17px;
/* background:url(图片路径) no-repeat scroll 95px center transparent; */
background: none;
}
/*这个是隐藏IE的*/
select::-ms-expand{
display:none;
}
select的父级::before {
position: absolute;
top: 1.7em;
right: 30px;
width:0;
height: 0;
padding: 0
content:";
border-left: 6px solid transparent;
border-right:6px solid transparent
border-top:6px solid #008856;
pointer-events: none;
}
7.CSS一行或多行文本,展示不下展示… :
单行文本展示不下,展示…
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
多行文本展示不下,展示…(适合于WebKit浏览器及移动端,对于IE浏览器兼容不好)
display:-webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp:3;//展示3行
overflow: hidden;
8.CSS设置浏览器滚动条:
::-webkit-scrollbar:滚动条整体部分,其中的属性:width,height,background,border等
::-webkit-scrollbar-button:滚动条两端的按钮。可以用displaynone让其不显示,也可以添加背景图片,颜色改变显示效果
::-webkit-scrollbar-track:外层轨道。可以用displaynone让其不显示,也可以添加背景图片,颜色改变显示效果
::-webkit-scrollbar-track-piece:内层轨道,具体区别看下面gif图,需要注意的就是它会覆盖第三个属性的样式。
::-webkit-scrollbar-thumb:滚动条里面可以拖动的那部分.-webkit-scrollbar-corner:边角,两个滚动条交汇处
::-webkit-resizer:两个滚动条交汇处用于拖动调整元素大小的小控件(基本用不上)
9.CSS伪元素清除浮动:
.clearfix:after{
content:"", /*设置内容为空*/
height:0; /*高度为0*/
line-height:0; /*行高为0*/
display:block; /*将文本转为块级元素*/
visibility:hidden /*将元素隐藏*/
clear:both; /*清除浮动*/
}
.clearfix{
zoom:1; /*为了兼容IE*/
}
10.CSS white-space 属性:
遇到br标签,都会换行
white-space:normal默认值 没有设置white-space属性,则默认为white-space:normal。
normal表示合并空格,多个相邻空格合并成一个空格,在源码中的换行作为空格处理,只会根据容器的大小进行自动换行。
white-space:nowrap 忽略空格、强制不换行
white-space:nowrap和normal一样,也合并空格,但是不会根据容器大小换行,表示不换行。
(这个效果在页面布局中使用很频繁,尤其在移动端布局中)
white-space:nowrap会导致文本不换行,经常和overflow,text-overflow一起使用(一行展示不下,展示…)
white-space:nowrap; overflow:hidden; text-overflow: ellipsis;
white-space:pre 保留空格、不换行
white-space:pre的作用是保持源码中的空格,有几个空格算几个空格显示,同时换行只认源码中的换行和标签。
效果很明显,源码中的换行在显示中也换行了,源码中的多个空格也保留了。并且pre在没有碰到源码换行和的时候是不换行了,不会去自适应容器换行。
white-space:pre-wrap 保留空格、换行
white-space:pre-wrap的作用是保留空格,并且除了碰到源码中的换行和会换行外,还会自适应容器的边界进行换行。
white-space:pre-wrap和white-space:pre的区别就是pre-wrap会自适应容器的边界进行换行。
white-space:pre-wrap 忽略空格、换行 在white-space:pre-wrap的基础上,忽略源码中空格
11.CSS点击穿透属性:
.noclick{
pointer-events: none;/*上层加上这句样式可以实现点击穿透*/
}
12.CSS设置input标签的placehoder属性样式:
input::-webkit-input-placeholder{
color: #ccc;/* WebKit, Blink, Edge */
}
input:-moz-placeholder{
color: #ccc;/* Mozilla Firefox 4 to 18*/
}
input::-moz-placeholder{
color: #ccc;/* Mozilla Firefox 19+ */
}
input:-ms-input-placeholder{
color: #ccc;/* Internet Explorer 10-11 */
}