css高级技巧汇总

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值