whoami
Lucas Jenß
cat /etc/motd
The Coding Journal ツ — Notes taken on an epic coding journey. Technical solutions, debugging notes, and practical guides from the trenches of software development.
ls -la ~/languages/
- drwxr-xr-x
- ▶ PHP
- ▶ Ruby
- ▶ Scala
- ▶ C#
- ▶ JavaScript
- ▶ Objective-C
- ▶ Shell Scripting
ls -la ~/toolchain/
- drwxr-xr-x
- ▶ Typo3
- ▶ Akka
- ▶ Capistrano
- ▶ Git
- ▶ MAMP
- ▶ Adobe Illustrator
- ▶ NSTrackingArea (Cocoa)
uname -a
- drwxr-xr-x
- ▶ Mac OS X
- ▶ Unix
Responsive SVGs That Fit Any Container Without JavaScript
Scalable Vector Graphics are well suited to responsive interfaces because they describe shapes mathematically rather than storing a fixed grid of pixels. A logo, map, diagram or icon can therefore remain sharp while its display size changes from a wide desktop panel to a narrow phone screen.
The key is separating the SVG’s internal coordinate system from the space available on the page. The viewBox defines the drawing, while CSS controls the rendered width. Once those roles are clear, responsive SVGs can adapt to their container without resize listeners, layout calculations or other JavaScript.
This approach is particularly useful for Australian websites, where visitors may move between large office monitors, tablets and mobile connections on the go. A visitor checking a service in Melbourne, browsing a property site from a Sydney train or using a phone during an arvo in Brisbane should receive the same usable graphic, scaled to the space available.
Build Around A Useful ViewBox
A responsive SVG normally starts with a viewBox, such as viewBox="0 0 800 450". The first two values establish the internal origin, and the final two values establish the artwork’s coordinate width and height. They also define the aspect ratio that the browser will preserve as the element changes size.
The root element can then use a fluid width:
<svg
class="hero-illustration"
viewBox="0 0 800 450"
width="800"
height="450"
role="img"
aria-labelledby="hero-title">
<title id="hero-title">A coastal delivery illustration</title>
<!-- Paths, groups and shapes -->
</svg>
The width and height attributes provide a useful intrinsic ratio, while the viewBox supplies the scalable coordinate system. They do not force the browser to render the graphic at 800 by 450 pixels when CSS overrides the display size.
A common mistake is exporting artwork with a large fixed canvas and no meaningful viewBox. The SVG may appear to scale, but its visible drawing can occupy only a small portion of that canvas. Remove unnecessary whitespace in Illustrator or another vector editor, then check the coordinate bounds in the source before adding responsive styles.
Let CSS Control The Rendered Width
For a block-level graphic, the essential CSS is short:
.hero-illustration {
display: block;
width: 100%;
height: auto;
max-width: 50rem;
}
width: 100% makes the SVG fill the width of its containing block, while height: auto preserves the ratio supplied by the viewBox and intrinsic dimensions. display: block prevents the small baseline gap that inline elements can produce beneath an image.
If the SVG is used as an external image, the same principle applies:
<img
class="chart"
src="/assets/chart.svg"
alt="Quarterly sales by region">
.chart {
display: block;
width: 100%;
height: auto;
}
An inline SVG gives you more control over its paths, fills and strokes, but it also places more markup in the document. An external SVG is easier to cache and reuse. Choose based on whether the graphic needs page-level styling or simply needs to scale cleanly.
The parent still matters. A child set to width: 100% can only respond to the width it receives. Use a sensible wrapper with a maximum width, padding and box-sizing: border-box so an illustration does not become awkwardly wide on a 4K monitor or collide with the edges of a narrow phone viewport.
Preserve The Drawing Without Distortion
The default preserveAspectRatio="xMidYMid meet" keeps the complete SVG visible and centres it inside the available box. This is generally right for diagrams, logos and illustrations where cropping would remove important information.
A banner may need a different treatment:
<svg
class="cover-art"
viewBox="0 0 1200 500"
preserveAspectRatio="xMidYMid slice"
aria-hidden="true">
<!-- Decorative artwork -->
</svg>
With slice, the drawing covers the entire viewport, but some edges can be clipped. It resembles object-fit: cover and works well for decorative backgrounds. Keep critical labels, faces and icons away from the likely crop area, or use separate layout rules for smaller screens.
SVG text deserves special care. Text elements do not wrap like HTML paragraphs, and a long label may run outside the visible area when the container becomes narrow. Prefer short labels, convert display lettering to paths when the typeface must be exact, or place explanatory text in HTML beside the graphic. Keeping content as HTML also improves translation, accessibility and search visibility.
Stroke widths can create another responsive issue. A line specified as stroke-width="8" remains eight units in the SVG coordinate system while the graphic scales. That may be desirable for a technical diagram, but it can look too heavy at a small size. vector-effect="non-scaling-stroke" keeps a stroke visually consistent, though it should be tested carefully where lines overlap or become very dense.
Use Layout Features Instead Of Script
SVG responsiveness works best when the outer layout is responsive too. Flexbox and Grid can allocate space around a graphic, while max-width, min-width and media queries handle practical limits. For example, a two-column product panel can collapse to one column without asking JavaScript to measure either element.
.product-panel {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(16rem, 30rem);
gap: 2rem;
align-items: center;
}
@media (max-width: 48rem) {
.product-panel {
grid-template-columns: 1fr;
}
}
The minmax(0, 1fr) detail is useful because it allows the text column to shrink instead of forcing the grid wider than its container. This prevents a large inline SVG or a long heading from causing horizontal scrolling.
For components reused in different parts of a site, CSS container queries can be more suitable than viewport media queries:
.card-shell {
container-type: inline-size;
}
@container (max-width: thirtyrem) {
.card-graphic {
margin-inline: auto;
}
}
In real CSS, replace the invalid word thirtyrem with a numeric value such as 30rem; the example highlights a frequent editing trap when writing breakpoint documentation. Container queries respond to the component’s available width rather than the whole browser window, which is valuable in dashboards, sidebars and CMS layouts.
JavaScript still has a place for interactions such as panning, zooming or changing data. It should not be needed merely to discover the container width and assign new SVG dimensions. Eliminating that measurement code reduces layout timing problems and makes the graphic work when scripts are blocked or deferred.
Test The Asset In Its Real Context
Check the graphic in more than one browser and at widths that reflect actual layouts. Test a narrow mobile viewport, a standard laptop, a wide monitor and a resized CMS column. Australian users may be on an older Android handset over a busy regional connection, so confirm that the SVG remains lightweight and that important information is visible without waiting for extra assets.
Inspect the result at common breakpoints around 320, 375, 768 and 1440 CSS pixels, then test intermediate widths. A graphic that looks fine at 375 and 768 pixels can still overflow at 540 pixels if a label, fixed group transform or wrapper margin has been overlooked. Browser developer tools make this inspection quick.
Accessibility testing should be part of the same check. Give informative artwork a concise <title> and an accessible name, or provide a longer adjacent description for a complex chart. Mark purely decorative SVGs with aria-hidden="true" and avoid repeating the same information in both the image and nearby text. Ensure colour contrast remains adequate, particularly for government, health and financial services that need to serve a broad Australian audience.
Keep troubleshooting notes alongside the source. When a build system, PHP template or asset pipeline behaves unexpectedly, isolate whether the issue is in the SVG, CSS or deployment process. The same habit helps with unrelated integration problems, such as Composer autoloading fixes, where a small reproducible example often exposes the real conflict faster than repeated configuration changes.
Practical Rules For Production SVGs
A small set of conventions keeps responsive vector assets predictable across projects. Record the intended aspect ratio, identify whether the artwork is decorative or meaningful, and avoid relying on a particular viewport width. If the asset is delivered through a content management system, confirm that the editor does not strip the viewBox during upload.
For a static site or a simple campaign page, place the SVG in the normal asset pipeline and serve it with compression and caching. A lightweight hosting setup such as simple web hosting can still deliver SVGs effectively when cache headers and file paths are configured consistently. The hosting provider is less important than preserving the source file and returning the correct image/svg+xml content type.
Use these recommendations during implementation:
- Keep a meaningful
viewBoxand remove accidental canvas whitespace. - Set
display: block,width: 100%andheight: autofor fluid graphics. - Use
preserveAspectRatio="meet"for complete diagrams andsliceonly when cropping is acceptable. - Move long explanations and wrapping text into HTML whenever possible.
- Test narrow containers, high-density displays, keyboard access and reduced-motion preferences.
Responsive SVGs become much easier to maintain when the drawing, container and accessibility roles are treated as separate concerns. Build the vector artwork around a deliberate coordinate system, let CSS size it, and reserve JavaScript for behaviour that genuinely requires interaction. Add one representative asset to your next project, inspect it across the layouts you actually support, and keep the working pattern in your project notes for reuse.
cat ~/interests.json
| Key | Value |
|---|---|
| editor | Terminal-first workflow |
| os | Mac OS X / Unix |
| vcs | Git, distributed version control |
| deploy | Capistrano, cron automation |
| graphics | SVG, Adobe Illustrator troubleshooting |
| networking | IP validation, SSH, VPN |
git log --oneline --reverse
Solving SVG import issues in Adobe Illustrator CS6 and CC
When importing an SVG into Illustrator, the operation fails with an unknown error [CANT]. A workaround for this Adobe-side bug.
Solving NDK build issues on OS X
Troubleshooting native development kit compilation problems on Mac OS X.
Programmatically adding PHP generated TypoScript to the backend configuration
Integrating dynamically generated TypoScript into Typo3 backend setups using PHP.
ArgumentError: Could not parse PKey: no start line
Debugging an SSH key parsing error encountered during deployment.
Validating IP-Addresses in PHP
Using PHP filter functions with flags like FILTER_FLAG_IPV4 and FILTER_FLAG_IPV6, and understanding how filter_var handles reserved IP addresses.
Cocoa: Using NSTrackingArea
A short tutorial on using Cocoa's NSTrackingArea to capture mouseEntered and mouseExited events.
cat ~/contact.txt