Sure! Below is a fully fledged HTML example containing multiple independently nested SVG elements with various weird dimension units and randomly missing or present viewBox attributes. This setup can be used for testing SVG rendering, scaling, and layout behavior.
<!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 {
background: #222;
color: #eee;
font-family: monospace, monospace;
padding: 20px;
}
section {
margin-bottom: 3rem;
border: 2px dashed #666;
padding: 10px;
}
svg {
background: #111;
display: block;
margin: 10px 0;
border: 1px solid #444;
}
</style>
</head>
<body>
<h1>Nested SVG Testing with Weird Dimensions and ViewBoxes</h1>
<section>
<h2>SVG #1 - Nested with missing viewBox</h2>
<svg width="200mm" height="100mm" xmlns="http://www.w3.org/2000/svg" >
<rect x="10mm" y="10mm" width="180mm" height="80mm" fill="#4466aa" />
<svg x="20mm" y="20mm" width="50ex" height="30ex" >
<circle cx="25ex" cy="15ex" r="10ex" fill="tomato" />
<svg x="5ex" y="5ex" width="30ex" height="10ex">
<rect x="0" y="0" width="30ex" height="10ex" fill="yellow" opacity="0.5" />
<text x="15ex" y="7ex" font-size="5ex" fill="#222" text-anchor="middle" dominant-baseline="middle">
Weird nested
</text>
</svg>
</svg>
</svg>
</section>
<section>
<h2>SVG #2 - Nested with mixed units and viewBox randomly present</h2>
<svg width="30vw" height="15vw" viewBox="0 0 300 150" xmlns="http://www.w3.org/2000/svg">
<rect x="0" y="0" width="100%" height="100%" fill="#2a9d8f" />
<svg x="25%" y="25%" width="50%" height="50%" viewBox="0 0 50 25" >
<ellipse cx="25" cy="12.5" rx="20" ry="10" fill="#e76f51" />
<svg x="5" y="5" width="40" height="15" >
<line x1="0" y1="0" x2="40" y2="15" stroke="navy" stroke-width="2" />
<line x1="0" y1="15" x2="40" y2="0" stroke="navy" stroke-width="2" />
</svg>
</svg>
</svg>
</section>
<section>
<h2>SVG #3 - Weird units, some with viewBox, some without</h2>
<svg width="15cm" height="8cm" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 150 80">
<rect width="100%" height="100%" fill="#264653" />
<svg x="3cm" y="2cm" width="9cm" height="4cm" >
<circle cx="4.5cm" cy="2cm" r="1.5cm" fill="orange" />
<svg x="1cm" y="1cm" width="7cm" height="2cm" viewBox="0 0 70 20">
<text x="35" y="15" fill="#000" font-size="15" font-family="Arial" text-anchor="middle">
Nested text
</text>
</svg>
</svg>
</svg>
</section>
<section>
<h2>SVG #4 - Missing viewBox and mixing px with % and em</h2>
<svg width="400px" height="200px" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" fill="#f4a261" />
<svg x="10%" y="20%" width="15em" height="12em" >
<rect x="0" y="0" width="15em" height="12em" fill="#e9c46a" />
<svg x="1em" y="1em" width="13em" height="10em">
<polygon points="0,0 13em,0 6.5em,10em" fill="#264653" />
<text x="6.5em" y="6em" fill="#fff" font-size="4em" text-anchor="middle" dominant-baseline="middle">
PX/%/EM
</text>
</svg>
</svg>
</svg>
</section>
<section>
<h2>SVG #5 - Using vw, vh, missing nested viewBox</h2>
<svg width="40vw" height="20vh" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 200">
<rect width="100%" height="100%" fill="#8ecae6" />
<svg x="10vw" y="5vh" width="20vw" height="10vh" >
<rect width="100%" height="100%" fill="#219ebc" />
<svg x="2vw" y="2vh" width="16vw" height="6vh">
<circle cx="8vw" cy="3vh" r="3vh" fill="#023047" />
</svg>
</svg>
</svg>
</section>
<section>
<h2>SVG #6 - Mix of empty viewBox, zero and missing</h2>
<svg width="300" height="150" xmlns="http://www.w3.org/2000/svg" viewBox="">
<rect x="0" y="0" width="300" height="150" fill="#f94144" />
<svg x="50" y="25" width="200" height="100" >
<ellipse cx="100" cy="50" rx="60" ry="40" fill="#f3722c" />
<svg x="25" y="10" width="150" height="80" viewBox="0 0 150 80">
<text x="75" y="40" font-family="sans-serif" font-size="20" fill="#fff" text-anchor="middle" dominant-baseline="middle">
Empty viewBox above
</text>
</svg>
</svg>
</svg>
</section>
<section>
<h2>SVG #7 - Nested SVG with % used as dimensions inside SVG without viewBox</h2>
<svg width="250px" height="120px" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" fill="#06d6a0" />
<svg x="10%" y="10%" width="80%" height="80%">
<rect width="100%" height="100%" fill="#118ab2" />
<svg x="5%" y="5%" width="90%" height="90%">
<circle cx="50%" cy="50%" r="40%" fill="#073b4c" />
</svg>
</svg>
</svg>
</section>
</body>
</html>
Explanation:
- Each section demonstrates a different nesting style and dimension unit usage including
mm, ex, em, px, cm, %, vw, vh.
viewBox attribute is randomly added, empty (viewBox=""), or missing on nested SVGs.
- Nested SVG coordinates (
x, y) and sizes sometimes use different units to stress-test layouts.
- Various SVG elements (
rect, circle, ellipse, line, polygon, text) are used to visualize the nesting more clearly.
- Background colors and borders help visually separate nested SVG layers.
- The text is added to verify text rendering inside nested SVGs.
Feel free to save and open this in any modern browser and check how the embedded SVGs render and scale with different unit types and missing viewBox attributes. Let me know if you'd like me to adjust or create other specific test cases!