iis服务器助手广告广告
返回顶部
首页 > 资讯 > 前端开发 > html >CSS怎么让一张彩色的图片显示为黑白照片
  • 770
分享到

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

2024-04-02 19:04:59 770人浏览 八月长安
摘要

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

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

一、黑白图像

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

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: <div class="test">

<span>

<input type="text" value="" readonly="true"/>

<a href="http://renpingjun.com">Double click me</a>

</span>

</div>

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

--结束END--

本文标题: CSS怎么让一张彩色的图片显示为黑白照片

本文链接: https://www.lsjlt.com/news/91873.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • CSS怎么让一张彩色的图片显示为黑白照片
    这篇文章主要介绍“CSS怎么让一张彩色的图片显示为黑白照片”,在日常操作中,相信很多人在CSS怎么让一张彩色的图片显示为黑白照片问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”...
    99+
    2022-10-19
  • 怎么用CSS background 控制显示图片的一部分
    本篇内容介绍了“怎么用CSS background 控制显示图片的一部分”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能...
    99+
    2022-10-19
软考高级职称资格查询
推荐阅读
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作