Рет қаралды 102,811
SVGs are strange. They have a lot of numbers and other strange stuff going on, and the viewBox can be really strange. But it's not that bad really. To understand how the viewBox works though, the first thing we need to do is understand what the SVG viewport is.
The viewport is sort of like our browser window. A website is larger than our browser window, which is why we have to scroll. SVGs are a bit like that too, we have a viewport that allows us to look at the SVG canvas. That viewport is the size of the SVG in our code, but the SVG canvas can be much larger!
The SVG viewBox is different. This is what we use to zoom in and out and pan around. The viewport stays the same. Picture opening something in Photoshop, then zooming in and panning around. You aren't changing the size of your Photoshop window at all (that's the viewport), but instead your moving items around on your screen (moving around the viewBox).
---
I have a newsletter! www.kevinpowel...
New to Sass, or want to step up your game with it? I've got a course just for you: www.kevinpowel...
---
My Code Editor: VS Code - code.visualstu...
How my browser refreshes when I save: • How to automatically r...
---
Support me on Patreon: / kevinpowell
I'm on some other places on the internet too!
If you'd like a behind the scenes and previews of what's coming up on my KZfaq channel, make sure to follow me on Instagram and Twitter.
Instagram: / kevinpowell.co
Twitter: / kevinjpowell
Codepen: codepen.io/kev...
Github: github.com/kev...