惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
博客园_首页
雷峰网
雷峰网
V
V2EX
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - Franky
月光博客
月光博客
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
T
Tailwind CSS Blog
小众软件
小众软件
博客园 - 叶小钗
美团技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
IT之家
IT之家
MyScale Blog
MyScale Blog
Blog — PlanetScale
Blog — PlanetScale
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
人人都是产品经理
人人都是产品经理
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

鬼影的基地

RSA:从 00 开始的钥匙串导入崩溃 RSA:从 00 开始的钥匙串导入崩溃 CVE-2025-61638:Sanitizer::validateAttributes data-XSS 萌娘百科水平越权漏洞 萌娘百科头像魔术字 IP 泄露 萌娘百科评论区 IP 泄露 修复 iPhone 13 iOS 16 Safari 中的 Bug 命名空间 在 CSS 中进行数据类型转换 在 iOS 的 Apple Mail 中添加 QQ邮箱 CodeMirror url() Bug Safari animation Bug 在 macOS 上部署 Viper CSS 自适应简单 Table
CSS 像素画的方法
鬼影233 · 2026-06-02 · via 鬼影的基地

前言

暴力的 div、table 堆叠不在此进行赘述,image-rendering、svg 与 canvas 不在范围内。

Box-shadow

代码写起来较为简短,也有很多的生成器。但一般需要再套个元素在外以帮助占位,浏览器缩放会影响显示效果(存在缝隙或堆叠),且不太方便自适应。

CSS Pixel Art Generator PIXEL ART TO CSS

展示柜

Linear-gradient

只需一个元素,十分方便的自适应,只需宽与高任意指定一个,甚至可以在里面写点字。但不支持透明,且代码又长又没什么生成器,写起来会不太方便。此外还应当设置 print-color-adjust: exact

简易生成代码

Mushroom linear-gradient
/** 代码修改自https://codepen.io/cgreinhold/pen/rNagxoK **/
const pixels = [
	["","#F00"],
	["#0F0","#00F"]
];

const pixelArt = document.getElementById("pixelart");
const width = pixels[0].length;
const height = pixels.length;

const backgroundImage = [];
const backgroundSize = [];
for (let i = 0; i < pixels.length; i++) {
	const pixel = pixels[i];
	const percent = 100 / pixel.length;
	let cont = 0;
	const backgroundParts = [];
	for (let j = 0; j < pixel.length; j++) {
		const pixelColor = pixel[j] || "#FFF";
		let backgroundImagePart = "";
		backgroundImagePart += `${pixelColor} ${cont}%`;
		cont += percent;
		backgroundImagePart += `, ${pixelColor} ${cont}%`;
		backgroundParts.push(backgroundImagePart);
	}
	backgroundImage.push(
		`linear-gradient(to right, ${backgroundParts.join(", ")})`
	);
	backgroundSize.push(`100% ${((i + 1) * 100) / height}%`);
}
pixelArt.style.aspectRatio = width / height;
pixelArt.style.backgroundImage = backgroundImage.join(",");
pixelArt.style.backgroundRepeat = "repeat-x";
pixelArt.style.backgroundSize = backgroundSize.join(",");
pixelArt.removeAttribute("id")

展示柜