网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

CSS怎么让一张彩色的图片显示为黑白照片

这篇文章主要介绍“CSS怎么让一张彩色的图片显示为黑白照片”,在日常操作中,相信很多人在CSS怎么让一张彩色的图片显示为黑白照片问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”CSS怎么让一张彩色的图片显示为黑白照片”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

网站建设公司,为您提供网站建设,网站制作,网页设计及定制网站建设服务,专注于企业网站制作,高端网页制作,对雨棚定制等多个行业拥有丰富的网站建设经验的网站建设公司。专业网站设计,网站优化推广哪家好,专业seo优化排名优化,H5建站,响应式网站。

一、黑白图像

当你需要让一张彩色的图片显示为黑白照片的时候,你可以用下面的一段代码。

img.desaturate{

filter: grayscale(100%);

-webkit-filter: grayscale(100%);

-moz-filter: grayscale(100%);

-ms-filter: grayscale(100%);

-o-filter: grayscale(100%);

}

二、使用 :not() 在菜单上应用/取消应用边框

先给每一个菜单项添加边框

.nav li{

border-right: 1px solid #666;

}

然后再除去最后一个元素

.nav li:last-child{

border-right: none;

}

也可以直接使用 :not() 伪类来应用元素

.nav li:not(:last-child){

border-right: 1px solid #666

}

如果你的元素有兄弟元素的话,也可以使用通用的兄弟选择符( ~ )

.nav li:first-child ~ li{

border-left: 1px solid #666

}

三、页面顶部阴影

给网页加上漂亮的顶部阴影效果

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;

}

四、给 body 添加行高

不需要给别给 p,h之类的添加行高,直接:

body{

line-height: 1;

}

五、所有一切都垂直居中

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

六、逗号分隔列表

让HTML列表项看上去像被一个真正的,分隔的列表

ul > li:not(:last-child)::after{

content: ",";

}

七、使用负的 nth-child 选择项目

在 css 中使用负的 nth-child 选择项目1到项目n

li{

display: none;

}

li:nth-child(-n+3){

display: block;

}

八、对图标使用 SVG

.logo{

background: url("logo.svg");

}

九、优化显示文本

有时候,字体并不能在所有设备上都达到最佳的显示,所以可以让设备浏览器来帮助你

html{

-moz-osx-font-smoothing: grayscale;

-webkit-font-smoothing: antialiased;

text-rendering: optimizelegibility;

}

十、对纯 css 滑块使用 max-height

使用 max-height 和溢出隐藏来实现只有 css 的滑块

.slider ul{

max-height: 0;

overflow: hidden;

}

.slider:hover ul{

max-height: 1000px;

transition: .3s ease;

}

十一、继承 box-sizing

让 box-sizing 继承 html

html{

box-sizing: border-box;

}

*,*:before, *:after{

box-sizing: inherit;

}

十二、表格单元格等宽

.table{

table-layout: fixed;

}

十三、 用 Flexbox 摆脱外边距的各种 hack

当你需要用到列分隔符时,通过flexbox的 space-between 属性,你就可以摆脱 nth- first- last-chlid 的 hack 了

.list{

display: flex;

justify-content: space-between;

}

.list .person{

flex-basis: 23%;

}

十四、使用属性选择器用于空链接

当 a 元素没有文本值,但是 href 属性有链接的时候显示链接

a[href^="http"]:empty::before{

content: attr(href);

}

十五、检测鼠标双击

HTML:

CSS:.test span{

position: relative;

}

.test span a{

position: relative;

z-index: 2;

}

.test span a:hover,.test span a:active{

z-index: 4;

}

.test span input{

background-color: transparent;

border: 0;

cursor: pointer;

position: absolute;

top: -1px;

left: 0;

width: 101%;

height: 301%;

z-index: 3;

}

.test span input:focus{

background-color: transparent;

border: 0;

z-index: 1;

}

十六、 CSS 写出三角形

div.arrow-up{

width: 0px;

height: 0px;

border-left: 5px solid transparent;

border-right: 5px solid transparent;

border-bottom: 5px solid #ccc;

font-size: 0px;

line-height: 0px;

}

div.arrow-down{

width: 0px;

height: 0px;

border-bottom: 5px solid transparent;

border-top: 5px solid transparent;

border-right: 5px solid #ccc;

font-size: 0px;

line-height: 0px;

}

div.arrow-left{

width: 0px;

height: 0px;

border-bottom: 5px solid transparent;

border-top: 5px solid transparent;

border-left: 5px solid #ccc;

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 #ccc;

font-size: 0px;

line-height: 0px;

}

十七、 CSS calc() 的使用

calc() 用法类似于函数,能够给元素设置动态的值

.simpleBlock{

width: calc(100% - 100px);

}

.complexBlock{

width: calc(100% - 50% / 3);

padding: 5px calc(3% - 2px);

margin-left: calc(10% + 10px);

}

十八、文本渐变

h3[data-text]{

position: relative;

}

h3[data-text]::after{

content: attr(data-text);

z-index: 10;

color: #e3e3e3;

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)));

}

十九、禁用鼠标事件

.disabled{

pointer-events: none;

}

二十、模糊文本

.blur{

color: transparent;

text-shadow: 0 0 5px rgba(0,0,0,.5);

}

到此,关于“CSS怎么让一张彩色的图片显示为黑白照片”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!


本文题目:CSS怎么让一张彩色的图片显示为黑白照片
URL链接:http://bjjierui.cn/article/gsjpdj.html

其他资讯