height svg by font size

i have many text on site and some time i need add SVG icon in text in: p,h1,span,ul and other text based components.
How i can set SVG hight by text in this tags without FLEX?
i try line-height, height: 100%, dont help…

<h1>Hello <svg class="heightByFontSize"></svg> world!</h1>
<p>Hello <svg class="heightByFontSize"></svg> world!</p>
<span>Hello <svg class="heightByFontSize"></svg> world!</span>

.heightByFontSize{
    // ????
}

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

.heightByFontSize {
  height: 0.7em;
  width: auto;
}
<h1>Hello <svg viewBox="0 0 30 30" class="heightByFontSize"><rect x="0" y="0" height="30" width="30" /></svg> world!</h1>
<p>Hello <svg viewBox="0 0 30 30" class="heightByFontSize"><rect x="0" y="0" height="30" width="30" /></svg> world!</p>
<span>Hello <svg viewBox="0 0 30 30" class="heightByFontSize"><rect x="0" y="0" height="30" width="30" /></svg> world!</span>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x