svg - 如何并排放置<rect>?

标签 svg

我想将 SVG 中的填充方 block 彼此相邻放置,但它们之间有细线。如何消除这些线条?

示例:

    <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="3cm" height="3cm" viewBox="0 0 10 10">
        <rect x="0" y="0" width="1" height="1" fill="black" />
        <rect x="2" y="0" width="1" height="1" fill="black" />
        <rect x="4" y="0" width="1" height="1" fill="black" />
        <rect x="6" y="0" width="1" height="1" fill="black" />
        <rect x="8" y="0" width="1" height="1" fill="black" />
        <rect x="0" y="1" width="1" height="1" fill="black" />
        <rect x="2" y="1" width="1" height="1" fill="black" />
        <rect x="3" y="1" width="1" height="1" fill="black" />
        <rect x="4" y="1" width="1" height="1" fill="black" />
        <rect x="5" y="1" width="1" height="1" fill="black" />
        <rect x="6" y="1" width="1" height="1" fill="black" />
        <rect x="7" y="1" width="1" height="1" fill="black" />
        <rect x="9" y="1" width="1" height="1" fill="black" />
        <rect x="0" y="2" width="1" height="1" fill="black" />
        <rect x="2" y="2" width="1" height="1" fill="black" />
        <rect x="8" y="2" width="1" height="1" fill="black" />
        <rect x="0" y="3" width="1" height="1" fill="black" />
        <rect x="1" y="3" width="1" height="1" fill="black" />
        <rect x="3" y="3" width="1" height="1" fill="black" />
        <rect x="5" y="3" width="1" height="1" fill="black" />
        <rect x="6" y="3" width="1" height="1" fill="black" />
        <rect x="8" y="3" width="1" height="1" fill="black" />
        <rect x="9" y="3" width="1" height="1" fill="black" />
        <rect x="0" y="4" width="1" height="1" fill="black" />
        <rect x="1" y="4" width="1" height="1" fill="black" />
        <rect x="5" y="4" width="1" height="1" fill="black" />
        <rect x="6" y="4" width="1" height="1" fill="black" />
        <rect x="8" y="4" width="1" height="1" fill="black" />
        <rect x="0" y="5" width="1" height="1" fill="black" />
        <rect x="3" y="5" width="1" height="1" fill="black" />
        <rect x="4" y="5" width="1" height="1" fill="black" />
        <rect x="9" y="5" width="1" height="1" fill="black" />
        <rect x="0" y="6" width="1" height="1" fill="black" />
        <rect x="5" y="6" width="1" height="1" fill="black" />
        <rect x="6" y="6" width="1" height="1" fill="black" />
        <rect x="8" y="6" width="1" height="1" fill="black" />
        <rect x="0" y="7" width="1" height="1" fill="black" />
        <rect x="4" y="7" width="1" height="1" fill="black" />
        <rect x="5" y="7" width="1" height="1" fill="black" />
        <rect x="6" y="7" width="1" height="1" fill="black" />
        <rect x="8" y="7" width="1" height="1" fill="black" />
        <rect x="9" y="7" width="1" height="1" fill="black" />
        <rect x="0" y="8" width="1" height="1" fill="black" />
        <rect x="1" y="8" width="1" height="1" fill="black" />
        <rect x="2" y="8" width="1" height="1" fill="black" />
        <rect x="7" y="8" width="1" height="1" fill="black" />
        <rect x="8" y="8" width="1" height="1" fill="black" />
        <rect x="0" y="9" width="1" height="1" fill="black" />
        <rect x="1" y="9" width="1" height="1" fill="black" />
        <rect x="2" y="9" width="1" height="1" fill="black" />
        <rect x="3" y="9" width="1" height="1" fill="black" />
        <rect x="4" y="9" width="1" height="1" fill="black" />
        <rect x="5" y="9" width="1" height="1" fill="black" />
        <rect x="6" y="9" width="1" height="1" fill="black" />
        <rect x="7" y="9" width="1" height="1" fill="black" />
        <rect x="8" y="9" width="1" height="1" fill="black" />
        <rect x="9" y="9" width="1" height="1" fill="black" />
    </svg>

我的声誉不允许我发布图片,但你可以仔细看看我的头像。

最佳答案

您会看到抗锯齿正在发挥作用。

将 shape-rendering="crispEdges"添加到根 <svg>元素(或者每个矩形)以获得您想要的显示。

关于svg - 如何并排放置<rect>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16150597/

相关文章:

c# - 从 ByteString 识别光栅(jpg、png 等)或 svg 文件格式

html - 使用 CSS3 自定义形状和动画

svg - SVG 中的零笔画宽度

html - 在 Firefox 中忽略来自 SVG 中心的 CSS transform-origin

javascript - 使用 Canvas 绘制包含 SVG 源的 img 以获取数据 URL

css - 是否可以在 ngClass 中传递 html 属性?

css - 使用 css::after 绘制 svg 元素

javascript - SVG 图像 url 在 Chrome 但在 Firefox 中不起作用?

javascript - 如何在 svg 和 d3.js 中指向线的交点?

html - SVG `viewbox` 应该在 `symbol` 中定义一次,还是每次 SVG 都是 `used` ?