Certainly! Below is an HTML file containing nested SVG elements with a variety of weird dimension units (like em, ex, vw, vh, %, ch, rem) and randomly present or missing viewBox attributes. The SVGs are independent, weirdly sized, and some have nested SVGs inside.
This setup can be used for testing rendering, dimension parsing, and viewBox handling.
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Nested Weird SVG Test</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 2rem;
background: #f4f4f4;
}
svg {
margin: 1rem;
border: 1px solid #333;
background: #fff;
}
</style>
</head>
<body>
<h1>Nested Weird SVGs Test</h1>
<!-- SVG 1: Dimensions in em, with viewBox -->
<svg width="15em" height="10em" viewBox="0 0 150 100" style="background:#fee;">
<rect x="10" y="10" width="130" height="80" fill="lightcoral" />
<!-- Nested SVG: no viewBox, dimensions in % -->
<svg x="30%" y="30%" width="50%" height="50%">
<circle cx="50%" cy="50%" r="40%" fill="navy" />
</svg>
</svg>
<!-- SVG 2: Dimensions in vw/vh, without viewBox -->
<svg width="20vw" height="20vh" style="background:#efe;">
<rect x="5vw" y="5vh" width="10vw" height="10vh" fill="orange" />
<!-- Nested SVG with viewBox -->
<svg x="7vw" y="7vh" width="6vw" height="6vh" viewBox="0 0 60 60" >
<polygon points="30,0 60,60 0,60" fill="purple" />
</svg>
</svg>
<!-- SVG 3: Dimensions in ch and rem, missing viewBox -->
<svg width="30ch" height="15rem" style="background:#eef;">
<line x1="0" y1="0" x2="30ch" y2="15rem" stroke="green" stroke-width="2" />
<!-- Nested SVG with weird dimension units and viewBox -->
<svg x="5ch" y="5rem" width="15ch" height="7rem" viewBox="0 0 150 70">
<ellipse cx="75" cy="35" rx="70" ry="30" fill="gold" />
</svg>
</svg>
<!-- SVG 4: Dimensions in percentages, with viewBox -->
<div style="width: 50vw; height: 30vh; border: 1px solid #888; margin: 2rem 0;">
<svg width="100%" height="100%" viewBox="0 0 200 120" style="background:#ffe;">
<rect width="200" height="120" fill="teal" />
<!-- Nested SVG without viewBox, dimension in px -->
<svg x="50" y="30" width="100px" height="60px" >
<text x="10" y="30" font-size="20" fill="white">Nested</text>
<circle cx="50" cy="30" r="25" fill="red" opacity="0.6" />
</svg>
</svg>
</div>
<!-- SVG 5: No dimension attributes, with viewBox -->
<svg viewBox="0 0 100 100" style="background:#def;">
<path d="M10 80 Q 52.5 10, 95 80 T 180 80" stroke="navy" fill="transparent" stroke-width="2" />
<!-- Nested SVG, dimension in % but no viewBox -->
<svg x="10" y="10" width="80%" height="80%" >
<rect x="0" y="0" width="100" height="100" fill="lime" fill-opacity="0.3"/>
</svg>
</svg>
<!-- SVG 6: Weird combination - px and em, missing viewBox -->
<svg width="120px" height="8em" style="background:#ffd;">
<circle cx="60" cy="4em" r="3em" fill="pink" />
<!-- Nested: dimensions vw/vh, no viewBox -->
<svg x="20px" y="20px" width="10vw" height="10vh" >
<line x1="0" y1="0" x2="100" y2="100" stroke="brown" stroke-width="4" />
</svg>
</svg>
</body>
</html>
Explanation:
SVG 1 uses em units in width and height, with a nested SVG using %.
SVG 2 uses viewport width and height units (vw, vh) but no viewBox, nested has a viewBox.
SVG 3 uses ch and rem for size, missing viewBox on the parent, nested has viewBox.
SVG 4 is in a div sized by viewport units, parent SVG uses %, nested fixed px units, with and without viewBox.
SVG 5 has no width/height attributes but has viewBox; nested uses % but no viewBox.
SVG 6 mixes px and em in dimensions, both parent and nested missing viewBox.
This code produces multiple independent SVGs with differing units and viewBox presence to test rendering behavior.
Feel free to open this HTML in different browsers/devices or embed this in your test environment.