JyLie

vuePress-theme-reco JyLie    2017 - 2023
JyLie

Choose mode

  • dark
  • auto
  • light
主页
分类
  • API
  • HTML
  • css
  • vue
  • Linux
  • Docker
  • Webpack
  • WebGL
  • PixiJS
  • Github
  • BOM
  • XML
  • bug
  • ie
  • uniapp
  • IE
  • mysql
  • font
  • bom
  • canvas
  • video
  • html
  • JavaScript
  • js
  • 运算符
  • RegExp
  • 编码
  • MiniApp
  • nginx
  • Tool
  • node.js
  • cat
  • nodejs
  • protocol
  • URL
  • FLOW
  • DNS
  • Protocol
  • python
  • 安全
  • linux
  • shell
  • IDE
  • Packer
  • ViteJS
  • git
  • vendor
  • WebApp
  • WebView
  • Window API
  • webview
  • 规范
标签
时光轴
GitHub
author-avatar

JyLie

74

Article

79

Tag

主页
分类
  • API
  • HTML
  • css
  • vue
  • Linux
  • Docker
  • Webpack
  • WebGL
  • PixiJS
  • Github
  • BOM
  • XML
  • bug
  • ie
  • uniapp
  • IE
  • mysql
  • font
  • bom
  • canvas
  • video
  • html
  • JavaScript
  • js
  • 运算符
  • RegExp
  • 编码
  • MiniApp
  • nginx
  • Tool
  • node.js
  • cat
  • nodejs
  • protocol
  • URL
  • FLOW
  • DNS
  • Protocol
  • python
  • 安全
  • linux
  • shell
  • IDE
  • Packer
  • ViteJS
  • git
  • vendor
  • WebApp
  • WebView
  • Window API
  • webview
  • 规范
标签
时光轴
GitHub
  • 不可思议的混合模式 background-blend-mode 与 mix-blend-mode

    • 混合模式值
      • mix-blend-mode
        • 特性:
        • 常用场景
        • 案例
      • background-blend-mode
        • 特性:
        • 案例
      • 常用场景

      不可思议的混合模式 background-blend-mode 与 mix-blend-mode

      vuePress-theme-reco JyLie    2017 - 2023

      不可思议的混合模式 background-blend-mode 与 mix-blend-mode


      JyLie 2021-07-05 css

      持续更新...

      # 混合模式值

      mix-blend-mode: normal;          //正常
      mix-blend-mode: multiply;        //正片叠底
      mix-blend-mode: screen;          //滤色
      mix-blend-mode: overlay;         //叠加
      mix-blend-mode: darken;          //变暗
      mix-blend-mode: lighten;         //变亮
      mix-blend-mode: color-dodge;     //颜色减淡
      mix-blend-mode: color-burn;      //颜色加深
      mix-blend-mode: hard-light;      //强光
      mix-blend-mode: soft-light;      //柔光
      mix-blend-mode: difference;      //差值
      mix-blend-mode: exclusion;       //排除
      mix-blend-mode: hue;             //色相
      mix-blend-mode: saturation;      //饱和度
      mix-blend-mode: color;           //颜色
      mix-blend-mode: luminosity;      //亮度
      
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      multiply混合后通常颜色会加深,多用在白色背景图片和其他元素的混合,以及彩色纹理的合并上。
      screen混合后颜色会减淡,非常适合实现霓虹灯光效果,适合黑色背景素材和其他元素混合,非常实用。
      overlay在颜色值暗的时候,采用了类似“正片叠底”的算法,而颜色亮的时候,采用了类似“滤色”的算法。此混合模式比较适合实现文字水印效果。
      darken表示哪个颜色暗使用哪个颜色,在web开发中,给图形或文字着色会很实用。
      lighten是哪个颜色浅就表现为哪个颜色,在web开发中,给图形或文字着色会很实用。
      color-dodge颜色减淡混合模式可以用来保护底图的高光,适合处理高光下的人物照片。
      color-burn颜色加深混合模式可以用来保护底图的阴影,适合处理幽深秘境一类的照片,通过和特定的色彩进行混合,可以营造更加幽深的意境。
      hard-light的效果是强光,最终的混合效果就好像耀眼的聚光灯照射过来,表现为图像亮的地方更亮,暗的地方更暗。多用在图像表现处理上。
      soft-light的效果是柔光,最终的混合效果就好像发散的光源弥漫过来,表现效果和hard-light有类似之处,只是表现没有那么强烈。给图像着色的时候常用此混合模式。
      difference是差值效果,可以实现颜色的反色效果。
      exclusion的效果是排除,最终的混合效果和difference模式是类似的,区别在于exclusion的对比度要更低一些。
      
      接下来要介绍的4种混合模式都属于颜色系混合模式,在web开发中不常用,还是传统的图像表现处理领域用的较多。
      
      hue表示色调混合,最终的效果是混合后的颜色使用底层元素的亮度和饱和度,而使用上层元素的色调。
      saturation表示饱和度混合,混合后的颜色保留底图的亮度和色调,使用顶图的饱和度。
      color表示颜色混合,混合后的颜色保留底图的亮度,使用顶图的色调和饱和度。
      luminosity表示亮度混合,混合后的颜色保留底图的色调和饱和度,使用顶图的亮度,和color模式正好是相反的。
      
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18

      # mix-blend-mode

      定义了元素的内容应该与元素的直系父元素的内容和元素的背景如何混合。通俗理解为背景的混合模式。

      # 特性:

      • 面向多个 DOM 元素,受多个元素背景色影响;
      • 叠加对象可为:背景色与背景色、背景色与图片、图片与图片
      • 叠加特性受背景间的顺序影响

      # 常用场景

      • mix-blend-mode 默认情况下是会混合所有比起层叠顺序低的元素的,如果我们希望值混合某一两个元素,而不是全部,该怎么办呢?可以试试在不叠加的图片上使用 CSS3 isolation:isolate;

      # 案例

      <style>
        .box {
          background-color: #0074d9;
        }
        .inner {
          width: 256px;
          height: 256px;
          background: url(mm1.jpg) no-repeat;
          isolation: isolate; /* 使用后该元素会被隔离,不参加混合 */
        }
        .mode {
          position: relative;
          right: -100px;
          mix-blend-mode: darken;
        }
      </style>
      <div class="box">
        <div class="inner">
          <img src="mm2.jpg" class="mode" />
        </div>
      </div>
      
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21

      # background-blend-mode

      定义该元素的背景图片,以及背景色如何混合。通俗理解为背景的混合模式。

      # 特性:

      • 面向单个 DOM 元素,具有隔离性;
      • 叠加对象可为:背景色与背景色、背景色与图片、图片与图片
      • 叠加特性受背景间的顺序影响

      # 案例

      <style>
        .bg-blend {
          width: 300px;
          height: 300px;
          background: url('https://mdn.mozillademos.org/files/8543/br.png'),
            url('https://mdn.mozillademos.org/files/8545/tr.png') no-repeat center;
          background-blend-mode: screen;
        }
      </style>
      <div class="bg-blend" id="div-bg"></div>
      
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10

      # 常用场景

      • 纹理效果
      • 图标的变色
      • 背景提亮\变暗叠加

      # 相关文档

      • MDN-mix-blend-mode
      • MDN-background-blend-mode
      • 张鑫旭-CSS3 混合模式 mix-blend-mode/background-blend-mode 简介