Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

SVG img breaking out of containing DIV?

Hi everyone,

Below is some code im using and I have a DIV wrapping a IMG tag which is holding a SVG,

When I followed the course on SVG with Nick we scaled the SVG using its containing DIV,

As I have tried to do so my SVG breaks out of its container is there and error in my code i cannot seee??

<div class="logo-img"><!-- Wraps the DigiMouse Logo Image -->               
    <img src="img/logo-testsvg.svg" alt="digiouse logo" id="main-logo">               
</div><!-- **END Logo Image Wrap -->
.logo-img {
  margin-top: 1.2%;
  width: 80%;
  height: auto;
}

I am using flex box as my layout and am aware there is a few little bugs with percentage based widths and heights but am not sure if this is that actual situation..

any advice is much appreciated!

Craig

1 Answer

Is it breaking horizontally or vertically?

Have you tried setting the img to display: block; or width: 100%;?

Hi Sean,

The SVG was breaking horizontally, to correct the issue I had to as you suggested make the img width 100% and the containing div my desired width.

Surprising how simple the solutions normally are .....

Thanks for the help!

Craig