I’m able to use background-image
with a gradient to generate a stipple pattern for a div
(upper square), but I can’t seem to make an SVG element (lower square) use that as a fill.
I don’t want to use a defs
or pattern
definition as I’m using d3.js to create my SVGs, so ideally I’m looking for a pure CSS solution.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.stipple {
width: 200px;
height: 200px;
background-color: white;
background-image: radial-gradient(black 0.5px, transparent 0.5px),
radial-gradient(black 0.5px, transparent 0.5px);
background-size: 5px 5px;
background-position: 0 0, 2.5px 2.5px;
border: 2px solid black;
}
</style>
</head>
<body>
<div class="stipple"></div>
<svg width="200" height="200">
<rect width="200" height="200" class="stipple" />
</svg>
</body>
</html>