Link to home
Start Free TrialLog in
Avatar of dlearman1
dlearman1Flag for United States of America

asked on

Can I use the clamp function to scale an SVG image.

I would like to scale an svg image using the clamp function. Something like this:

<div class="l-wrapper-page">
       <a class="l-wrapper-page__logo" href="#"><img src="./_img/graphics/logos/serena-logo-sm.svg" width="clamp(140px, calc((#{.06544vw + 75.07853})) * 1px, 240px)" height="auto" alt="Serena Construction Logo">
      </a>
</div>

Open in new window

I've tried a few tweaks to the code, but nothing seems to work. Looking up clamp it is supposed to work wherever a length is called for.  Is there a reason this application doesn't work: relating to SVG or clamp specs?  Is there a way to modify the code so it will work?

Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

I just use width='nnpx' and the web browser automatically scales the SVG image to fit.  It even works with percentages.
Avatar of dlearman1

ASKER

Dave thanks for your input.
If possible, I'm looking for a dynamic solution that scales with viewer width. If I'm understanding you correctly, your solution would be static.

No, defining 'width' in percent is always dynamic.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK I'll give it a try.  Thanks