html - 线性渐变渲染问题firefox
问题描述
我正在尝试绘制几个不同大小的网格,但我遇到了 Firefox 的问题 -linear-gradient
在很多地方都对我造成了破坏。
它在提供任何单位(px/mm/%/rounded/float)的 Google Chrome 上都可以正常工作,但它在 Firefox 上做了一些有趣的事情。我尝试过使用不同的单位/舍入/前缀/3d hack,但这些都不起作用。
div {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-image: linear-gradient(to right, black 1px, transparent 1px),
linear-gradient(to bottom, black 1px, transparent 1px);
background-size: 5mm 5mm;
}
<div></div>
解决方案
1px
重复渐变应该会产生更好的结果,但是当涉及到像渐变这样的小值时,它总是很棘手
div {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-image:
repeating-linear-gradient(to right, black 0 1px, transparent 0 5mm),
repeating-linear-gradient(to bottom, black 0 1px, transparent 0 5mm);
}
<div></div>
你也可以在这里考虑一个 SVG(调整 viewBox、宽度和高度或矩形,直到你得到一个好的结果)
div {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background:
url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='black'> <rect x='0' y='0' width='1' height='100%' /> <rect x='0' y='0' width='100%' height='1'/></svg>")
0 0/5mm 5mm;
}
<div></div>
也像下面只有 SVG:
svg {
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
}
<svg xmlns="http://www.w3.org/2000/svg">
<defs>
<pattern id="grid" width="20" height="20" patternUnits="userSpaceOnUse">
<rect x='0' y='0' width='1' height='100%' />
<rect x='0' y='0' width='100%' height='1'/>
</pattern>
</defs>
<rect width="3000" height="3000" fill="url(#grid)" />
</svg>
推荐阅读
- php - 如何在 Laravel 4 中使用 put Method on Cache?
- javascript - 如何避免为 dataTables 中的每个按钮使用自定义脚本?
- rxjs - 可观察到的,它发出精确地按一定时间间隔分开的事件
- jwt - CAS JWT Service Ticket 文档中的“返回的断言长度”是什么意思?
- react-native - 显示 React Native 的 Flatlist 数组
- apollo - 使用 apollo-link-state 保存 @client 数据时出现“selectionSet 为空”错误
- r - 使用 Mtcars 示例在散点图中获得最佳拟合线
- getchar - Linux 上的 getchar() 可以读取哪些键盘字符
- javascript - 从动态路径中查找文件夹
- c# - 邻接矩阵中的 BFS