网格背景
Grid Background
横线与竖线重复排列,在内容背后形成细密的方格。
适用场景
给技术产品首屏、示意图或工作区铺一层低对比的底纹。 密集文字附近可以拉大格距,把清晰可见的网格留给需要制图感的区域。
应用示例
装修规划工具在示例户型图背后铺一层淡方格。画布像一张方格纸,房间宽度的标注也容易扫读。
也叫
- 方格背景
AI 提示词
用两个方向互相垂直的 CSS 渐变给【目标区块】加上 Grid Background。设置统一方格间距和较低对比度的线条颜色,并适配主题。网格置于内容背后,确保文字与按钮周围易于阅读。
示例代码
保存为 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;
}
.grid-sample {
--grid-line: #9680ce4d;
position: relative;
display: grid;
align-content: center;
justify-items: center;
gap: 9px;
width: min(100%, 276px);
min-height: 120px;
overflow: hidden;
border: 1px solid #584b79;
border-radius: 16px;
background-color: #28223e;
background-image:
linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
linear-gradient(var(--grid-line) 1px, transparent 1px);
background-position: center;
background-size: 17px 17px;
color: #efe7ff;
font-size: 14px;
font-weight: 700;
}
.grid-sample > span { position: relative; background: #28223e; }
.grid-sample > span:last-child { padding: 4px 8px; border-radius: 4px; }
.grid-cross { width: 16px; height: 16px; border: 1px solid #cbb3ff; }
.grid-cross::before, .grid-cross::after { position: absolute; inset: 50%; background: #cbb3ff; content: ''; }
.grid-cross::before { width: 26px; height: 1px; transform: translateX(-50%); }
.grid-cross::after { width: 1px; height: 26px; transform: translateY(-50%); }
</style>
</head>
<body>
<main class="demo">
<div class="grid-sample">
<span class="grid-cross" aria-hidden="true"></span>
<span>工作区</span>
</div>
</main>
</body>
</html>UI Skills 原创示例