我们如何向线性渐变背景添加噪音?

问题描述 投票:0回答:2

我们如何向线性渐变背景添加噪点?

body{
height: 100vh;
background:
linear-gradient(red, transparent ),
linear-gradient(to top left, blue, transparent),
linear-gradient(to top right, rgb(124, 211, 134), transparent );
background-blend-mode: screen;
}
css linear-gradients noise
2个回答
2
投票

这是一个仅 CSS 的解决方案(相关:https://css-tricks.com/making-static-noise-from-a-weird-css-gradient-bug/

body {
  height: 100vh;
  background: 
   repeating-conic-gradient(at 100%,#0000 0.000045%, #000d 0.0005%), /* your noise */
   linear-gradient(red, transparent), 
   linear-gradient(to top left, blue, transparent), 
   linear-gradient(to top right, rgb(124, 211, 134), transparent);
  background-blend-mode: overlay, screen, screen;
}


1
投票

使用

::pseudo
元素可以使用 2 种以上的颜色。

@import "https://cdn.jsdelivr.net/gh/KunalTanwar/normalize/css/normalize.inter.min.css";

body {
  height: 100%;
  display: grid;
  place-items: center;
}

.container {
  width: 150px;
  aspect-ratio: 1/1;
  background-image: linear-gradient(to right, #833ab4, #fd1d1d, #fcb045);
}
.container::after {
  content: "";
  position: absolute;
  inset: 0 0 0 0;
  width: 100%;
  height: 100%;
  mix-blend-mode: multiply;
  background-repeat: no-repeat;
  background-position: center center;
  background-image: url(https://grainy-gradients.vercel.app/noise.svg);
}
<div class="container"></div>

© www.soinside.com 2019 - 2024. All rights reserved.