1、彩色照片显示黑白照片
img.desaturate{
filter:grayscale(100%);
-webkit-filter:grayscale(100%);
-moz-filter:grayscale(100%);
-ms-filter:grayscale(100%);
-o-filter:grayscale(100%);
}
2、:not伪类的使用
.nva li:not(:last-child){
border-right:1px solid #666;
}
3、兄弟元素选择符的使用
.nav li:first-child~li{
border-left:1px solid #666;
}
4、页面顶部阴影
body:before{
content:"";
position:fixed;
top:-10px;
left:0;
width:100%;
height:10px;
-webkit-box-shadow:0px 0px 10px rgba(0,0,0,.8);
-moz-box-shadow:0px 0px 10px rgba(0,0,0,.8);
box-shadow:0px 0px 10px rgba(0,0,0,.8);
z-index:100;
}
5、body 添加行高
body{
line-height:1;
}
6、所有一切都垂直居中
html,body{
height:100%;
margin:0;
}
body{
-webkit-align-items:center;
-ms-flex-align:center;
align-items:center;
display:-webkit-flex;
display:flex;
}
// 注意:在ie11 中要小心flexbox
7、逗号分隔的列表
// 让html列表项看山去像正真的 , 用逗号分隔的列表
ul>li:not(:last-child)::after{
content:",";
}
// 对最后一个列表项使用:not()伪类
8、使用负的nth-child 选择项目
// 在css中使用负的nth-child 选择项目1 到项目n
li{
display:none;
}
li:nth-child(-n+3){
display:block;
}
9、对图标使用svg
.logo{
background:url("logo.svg");
}
10、优化显示文本
// 字体在所有设备上都达到最佳的显示
html{
-moz-osx-font-smoothing:grayscale;
-webkit-font-smoothing:antialiased;
text-rendering:optimizeLegibility;
}
11、对纯css滑块使用max-height
// 使用max-height 和溢出隐藏来实现只有css的滑块
.slider ul{
max-height:0;
overflow:hidden;
}
.slider:hover ul{
max-height:1000px;
transition:.3s ease;
}
12、继承box-sizing
html{
box-sizing:boder-box;
}
*,*:before,*:after{
box-sizing:inherit;
}
13 、 表格单元格等宽
.calendar{
table-layout:fixed;
}
14、使用属性选择器用于空链接
// 当a元素没有文本值,但href属性有链接的时候显示链接;
a[href^="http"]:empty::before{
content: attr(href);
}
15、模糊文本
.blur{
color:transparent;
text-shadow:0 0 5px rgba(0,0,0,.5);
}
16、禁用鼠标事件
// 一个链接如果设置了下面的样式就无法点击了
.disabled{
pointer-events:none;
}
17、文本渐变
h3[data-text]{
position:relative;
}
h3[data-text]::after{
content:attr(data-text);
z-index:10;
color:#ddd;
position:absolute;
top:0;
left:0;
-webkit-mask-image:-webkit-gradient(linear,left top,left bottom,from(rgba(0,0,0,0)), color-stop(50%,rgba(0,0,0,1)),to(rgba(0,0,0,0));)
}
18、css3 calc()的使用
.simpleBlock{
width:calc(100%-100px);
}
.complexBlock{
width:calc(100%-50%/3);
padding:5px calc(3%-px);
margin-left: calc(10%+10px);
}
19、css写出三角形
div.arrow-up{
width:0px;
height:0px;
border-lef:5px solid transparent;
border-right:5px solid transparent;
border-bottom:5px solid blue;
font-size:0px;
line-height:0px;
}
div.arrow-down{
width:0px;
height:0px;
border-left:5px solid transparent;
border-right:5px solid transparent;
border-top:5px solid red;
font-size:0px;
line-height:0px;
}
div.arrow-left{
width:0px;
height:0px;
border-bottom:5px solid transparent;
border-top:5px solid transparent;
border-right:5px solid green;
font-size:0px;
line-height:0px;
}
div.arrow-right{
width:0px;
height:0px;
border-bottom:5px solid transparent;
border-top:5px solid transparent;
border-left:5px solid orange;
font-size:0px;
line-height:0px;
}