镂空负形文字
Knockout Cutout Type
在不透明的版面中挖出字形空洞,让下层图案从笔画内部透出来。
适用场景
适合把短标志或首屏标题做成画面中的字形窗口。 用笔画宽的短词做开口,给下层图像留出可识别的面积。选图时留意笔画两侧的明暗对比。
应用示例
潜水学校的课程页用深蓝色遮罩盖住珊瑚礁照片,再挖出「潜入」两个字。读者透过字形看到下方的水下照片,报名信息放在下方的纯色区域。
AI 提示词
为【标题】制作镂空负形文字。将底层图案与实色面板分成独立图层,从面板中减去字形的透明度,让图案穿过真实开孔。标题保留为无障碍 DOM 文本,并检查不同图案位置下的可读性。
示例代码
保存为 HTML 文件后,用浏览器打开即可运行。代码与页面里的演示一致。
查看 HTML
<!doctype html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>镂空负形文字</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.specimen {
display: grid;
width: min(100%, 356px);
gap: 8px;
margin: 0;
justify-items: center;
}
.specimen canvas {
display: block;
width: 100%;
aspect-ratio: 2;
max-height: max(72px, calc(100vh - 65px));
border-radius: 11px;
background: linear-gradient(145deg, #232943, #14172c);
box-shadow: 0 8px 22px #090a16a8;
}
.specimen label {
display: grid;
width: 100%;
min-height: 25px;
grid-template-columns: minmax(0, auto) minmax(56px, 1fr);
align-items: center;
gap: 8px;
color: var(--demo-ink);
font-size: 12px;
}
.specimen input {
width: 100%;
margin: 0;
accent-color: #b9a6ff;
}
@media (prefers-reduced-motion: reduce) {
.specimen [data-loop-toggle] { display: none; }
}
</style>
</head>
<body>
<main class="demo">
<figure class="specimen">
<canvas role="img" aria-label="镂空负形文字" width="288" height="144">镂空负形文字</canvas>
<label for="specimen-setting">底图位置<input id="specimen-setting" type="range" min="0" max="100" value="47"></label>
</figure>
</main>
<script>
(() => {
const canvas = document.querySelector('.specimen canvas');
const ctx = canvas.getContext('2d');
if (!ctx) {
document.querySelector('.specimen :is(input, button)').disabled = true;
return;
}
const width = 288;
const height = 144;
const turn = Math.PI * 2;
let elapsed = 0;
let variation = 0.47;
function dot(x, y, radius, ink) {
ctx.fillStyle = ink;
ctx.beginPath();
ctx.arc(x, y, radius, 0, turn);
ctx.fill();
}
function mix(a, b, amount) {
return a + (b - a) * amount;
}
const face = document.createElement('canvas');
face.width = width;
face.height = height;
const mask = face.getContext('2d');
mask.fillStyle = '#262239';
mask.fillRect(0, 0, width, height);
mask.globalCompositeOperation = 'destination-out';
mask.font = '900 67px system-ui, sans-serif';
mask.textAlign = 'center';
mask.textBaseline = 'middle';
mask.fillText('CUT', 144, 72);
function draw(_time, amount) {
const offset = (amount - .5) * 180;
const pigment = ctx.createLinearGradient(offset, 0, width + offset, height);
pigment.addColorStop(0, '#f7cda4');
pigment.addColorStop(.45, '#b2dce8');
pigment.addColorStop(1, '#d686bb');
ctx.fillStyle = pigment;
ctx.fillRect(0, 0, width, height);
ctx.fillStyle = '#48478a7d';
for (let i = -4; i < 14; i++) {
const x = offset + i * 22;
ctx.beginPath();
ctx.moveTo(x - 10, 30);
ctx.lineTo(x + 8, 30);
ctx.lineTo(x + 99, 121);
ctx.lineTo(x + 78, 121);
ctx.closePath();
ctx.fill();
}
ctx.drawImage(face, 0, 0);
ctx.strokeStyle = '#dcc0e535';
ctx.strokeRect(16, 18, width - 32, height - 36);
}
function render() {
const ratio = Math.min(devicePixelRatio || 1, 2);
const pixelsWide = Math.max(1, Math.round(canvas.clientWidth * ratio));
const pixelsTall = Math.max(1, Math.round(canvas.clientHeight * ratio));
if (canvas.width !== pixelsWide || canvas.height !== pixelsTall) {
canvas.width = pixelsWide;
canvas.height = pixelsTall;
}
ctx.setTransform(pixelsWide / width, 0, 0, pixelsTall / height, 0, 0);
ctx.clearRect(0, 0, width, height);
ctx.save();
draw(elapsed, variation);
ctx.restore();
}
render();
new ResizeObserver(render).observe(canvas);
const input = document.querySelector('#specimen-setting');
input.addEventListener('input', () => {
variation = Number(input.value) / 100;
render();
});
})();
</script>
</body>
</html>UI Skills 原创示例