html - How to Make an SVG Image Dynamically Match the Height (1em) and the Baseline of Surrounding Text? -


is possible dynamically resize svg image (using html or css) match baseline , height of surrounding text?

something (the svg image being windows logo in situation):

image 1

image 2

the context clear images; want svg image match size of text no matter font face or font size viewer of page using.

if possible, should still match size of text if user zooms in page using browser’s zoom text only feature (like one):

support.mozilla.org/en-us/kb/font-size-and-zoom-increase-size-of-web-pages#w_how-to-only-change-the-size-of-the-text

i suppose that, effectively, want browser treat svg image if it’s text.

…i realize using web font may optimal solution in scenario, i’d rather avoid if can it. other being bit of ugly solution problem, creates new issues, like:

  • even if create web font myself, height of logo won’t (exactly) match em in every font in existence (although, @ least, sizes close)

  • there’s higher chance user have web fonts blocked on images

  • etc.

the naive answer set height of svg 1em. but, of course, want match x-height of font, not em height.

the news x-height consistent particular font, no matter how large is. once find right em value set svg size to, work whatever font size choose.

demo

svg.keyicon  {    width: 0.8m;    height: 0.8em;  }      .small  {    font: 24px arial;    color: black;  }    .large  {    font: 36px arial;    color: blue;  }
<div class="small">    press     <svg viewbox="0 0 100 100" class="keyicon">      <circle cx="50" cy="50" r="50" fill="currentcolor"/>    </svg>    key...  </div>      <div class="large">    press     <svg viewbox="0 0 100 100" class="keyicon">      <circle cx="50" cy="50" r="50" fill="currentcolor"/>    </svg>    key...  </div>


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -