当前位置: 首页 > news >正文

如何只用 CSS 制作网格?

来源:how-to-make-a-grid-like-graph-paper-grid-with-just-css

在看 用于打印到纸张的 CSS 这篇文章时,对其中的网格比较好奇,作者提供了 stackoverflow 的链接,就看到了来源的这个问题和众多回复。本文从里面挑选了一些个人比较喜欢的样式,贴在下面展示。

样式1

效果图:
在这里插入图片描述

样式代码:

<!DOCTYPE html>
<html>
<style>
html
{width: 100%;height: 100%;background-color: lightblue;background-size: 1cm 1cm;background-image:linear-gradient(to right, grey 1px, transparent 1px),linear-gradient(to bottom, grey 1px, transparent 1px);
}
</style>
<body><h1>Sample text</h1><h2>Sample text</h2><h3>Sample text</h3><h4>Sample text</h4><p>sample text</p><h1>示例文字</h1><h2>示例文字</h2><h3>示例文字</h3><h4>示例文字</h4><p>示例文字</p>
</body>
</html>

打印预览无边距时,选择A4纸时的尺寸和格子数量刚好一样,用这种背景比较方便做排版和套打,下图是打印后的效果:
在这里插入图片描述
和A4纸的尺寸 21.0 x 29.7厘米(8.27 x 11.69英寸) 是一致的。

样式2

效果图:
在这里插入图片描述

样式代码:

<!DOCTYPE html>
<html>
<style>
html
{width: 100%;height: 100%;background-color: lightblue;background-size: 40px 40px;background-image: radial-gradient(circle, #000000 1px, rgba(0, 0, 0, 0) 1px);
}
</style>
<body><h1>Sample text</h1><h2>Sample text</h2><h3>Sample text</h3><h4>Sample text</h4><p>sample text</p><h1>示例文字</h1><h2>示例文字</h2><h3>示例文字</h3><h4>示例文字</h4><p>示例文字</p>
</body>
</html>

样式3

效果图:
在这里插入图片描述

样式代码:

<!DOCTYPE html>
<html>
<style>
html
{width: 100%;height: 100%;background-color: lightblue;background:linear-gradient(-90deg, rgba(0,0,0,.05) 1px, transparent 1px),linear-gradient(rgba(0,0,0,.05) 1px, transparent 1px), linear-gradient(-90deg, rgba(0, 0, 0, .04) 1px, transparent 1px),linear-gradient(rgba(0,0,0,.04) 1px, transparent 1px),linear-gradient(transparent 3px, #f2f2f2 3px, #f2f2f2 78px, transparent 78px),linear-gradient(-90deg, #aaa 1px, transparent 1px),linear-gradient(-90deg, transparent 3px, #f2f2f2 3px, #f2f2f2 78px, transparent 78px),linear-gradient(#aaa 1px, transparent 1px),#f2f2f2;background-size:4px 4px,4px 4px,80px 80px,80px 80px,80px 80px,80px 80px,80px 80px,80px 80px;
}
</style>
<body><h1>Sample text</h1><h2>Sample text</h2><h3>Sample text</h3><h4>Sample text</h4><p>sample text</p><h1>示例文字</h1><h2>示例文字</h2><h3>示例文字</h3><h4>示例文字</h4><p>示例文字</p>
</body>
</html>

样式4

效果图:
在这里插入图片描述

样式代码:

<!DOCTYPE html>
<html>
<style>
html
{width: 100%;height: 100%;background-color: lightblue;--grid-size: 30px;--grid-strength: 1px;--grid-dash: 10px;--grid-gap: 5px;--grid-color: #ddd;--paper-color: #fff;background-color: var(--paper-color);background-size: var(--grid-dash) var(--grid-dash), var(--grid-size) var(--grid-size);background-image:linear-gradient(to bottom, transparent var(--grid-gap), var(--paper-color) var(--grid-gap)), linear-gradient(to right, var(--grid-color) var(--grid-strength), transparent var(--grid-strength)),linear-gradient(to right, transparent var(--grid-gap), var(--paper-color) var(--grid-gap)),linear-gradient(to bottom, var(--grid-color) var(--grid-strength), transparent var(--grid-strength));}
</style>
<body><h1>Sample text</h1><h2>Sample text</h2><h3>Sample text</h3><h4>Sample text</h4><p>sample text</p><h1>示例文字</h1><h2>示例文字</h2><h3>示例文字</h3><h4>示例文字</h4><p>示例文字</p>
</body>
</html>

http://www.mrgr.cn/news/34926.html

相关文章:

  • 从理论到实践:业务能力建模在数字化转型中的落地实施路径
  • 二.python基础语法
  • SpringBoot使用hutool操作FTP
  • 软设每日打卡——在一个页式存储管理系统中,页表内容如下所示: 若页的大小为4KB,则地址转换机构将逻辑地址0转换成物理地址(块号在0开始计算)为
  • 开创远程就可以监测宠物健康新篇章
  • 降维技术内涵及使用代码
  • C++(学习)2024.9.23
  • IM项目------消息存储子服务
  • CSS05-Emment语法
  • 搭建EMQX MQTT服务器并接入Home Assistant和.NET程序
  • C++ Practical-1 day4
  • 【Qualcomm】高通SNPE框架简介、下载与使用
  • JUC并发编程_ReadWriteLock
  • 【机器学习】---元强化学习
  • 【Qualcomm】高通SNPE框架的使用 | 原始模型转换为量化的DLC文件 | 在Android的CPU端运行模型
  • 大数据-146 Apache Kudu 安装运行 Dockerfile 模拟集群 启动测试
  • @JsonFormat与@DateTimeFormat的区别
  • 金九银十,字节的第一面来咯
  • (8)mysql容器启动第一次无论输入密码与否均会报错处理
  • Linux复习--网络基础(OSI七层、TCP三次握手与四次挥手、子网掩码计算)