Using display flex on a button makes it wrap in Firefox - html

For some reason using display Flex like this causes the items to wrap one ontop of eachother in Mozilla. Is there a reason for this? In Chrome it works fine and they are on one line in the middle.
FireFox
Chrome
button.primary {
display: -webkit-flex;
display: -moz-flex;
display: flex;
align-items: center;
padding: 10px 20px;
}
svg {
width: 15px
}
<button class="primary add-student">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0" y="0" viewBox="15.6 15.6 114.7 114.7" enable-background="new 15.6 15.6 114.7 114.7" xml:space="preserve" class="plus">
<path d="M128.1 59.6c-1.5-1.5-3.4-2.3-5.5-2.3H88.6V23.5c0-2.2-0.8-4-2.3-5.5 -1.5-1.5-3.4-2.3-5.5-2.3H65.2c-2.2 0-4 0.8-5.5 2.3s-2.3 3.4-2.3 5.5v33.9H23.5c-2.2 0-4 0.8-5.5 2.3s-2.3 3.4-2.3 5.5v15.6c0 2.2 0.8 4 2.3 5.5 1.5 1.5 3.4 2.3 5.5 2.3h33.9v33.9c0 2.2 0.8 4 2.3 5.5 1.5 1.5 3.4 2.3 5.5 2.3h15.6c2.2 0 4-0.8 5.5-2.3 1.5-1.5 2.3-3.4 2.3-5.5V88.6h33.9c2.2 0 4-0.8 5.5-2.3 1.5-1.5 2.3-3.4 2.3-5.5V65.2C130.4 63 129.6 61.2 128.1 59.6z"></path>
</svg><span>Add Student</span>
</button>

[UPDATE: Firefox trunk builds have changed to match the questioner's expectations on this issue. This change will tentatively be in Firefox 52, which I believe ships in March 2017.]
So, a few things:
The display property has almost no effect on a <button> in Firefox, as described in https://bugzilla.mozilla.org/show_bug.cgi?id=984869, aside from letting you choose whether the button is block-level or inline-level. (This is also true of <table> and <fieldset>, in both Chrome and Firefox.)
The effect you're seeing (wrapping) is happening because of a quirk of flexbox -- things with display:flex force their children to be block-level. So, your <svg> and <span> elements become display:block instead of their default display:inline, and so they each get their own line (because they're each a block now). This happens even though the button doesn't actually become a flex container, because all the style system sees is style data -- so it sees "display:flex" on the parent & blockifies the children. It doesn't know that we happen to be on a <button> which is special and not-actually-a-flex-container. This might be arguably a bug in Firefox; I'm not sure, offhand.
ANYWAY - if you're trying to set dipslay:flex on a <button>, what you actually need is a wrapper-div inside your <button>, to contain the <svg> and <span>, and which you can style to be a flex container.
Here's an updated version of your code snippet (with -moz prefixed version removed, since as another answer pointed out, -moz-flex isn't recognized in any supported version of Firefox):
div.buttonContents {
display: -webkit-flex;
display: flex;
align-items: center;
}
button.primary {
padding: 10px 20px;
}
svg {
width: 15px
}
<button class="primary add-student">
<div class="buttonContents">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0" y="0" viewBox="15.6 15.6 114.7 114.7" enable-background="new 15.6 15.6 114.7 114.7" xml:space="preserve" class="plus">
<path d="M128.1 59.6c-1.5-1.5-3.4-2.3-5.5-2.3H88.6V23.5c0-2.2-0.8-4-2.3-5.5 -1.5-1.5-3.4-2.3-5.5-2.3H65.2c-2.2 0-4 0.8-5.5 2.3s-2.3 3.4-2.3 5.5v33.9H23.5c-2.2 0-4 0.8-5.5 2.3s-2.3 3.4-2.3 5.5v15.6c0 2.2 0.8 4 2.3 5.5 1.5 1.5 3.4 2.3 5.5 2.3h33.9v33.9c0 2.2 0.8 4 2.3 5.5 1.5 1.5 3.4 2.3 5.5 2.3h15.6c2.2 0 4-0.8 5.5-2.3 1.5-1.5 2.3-3.4 2.3-5.5V88.6h33.9c2.2 0 4-0.8 5.5-2.3 1.5-1.5 2.3-3.4 2.3-5.5V65.2C130.4 63 129.6 61.2 128.1 59.6z"></path>
</svg><span>Add Student</span>
</div>
</button>

I would use more light weight method for buttons display:inline-block:
button {
height: 40px;
padding: 0 10px;
white-space: nowrap;}
button * {
display: inline-block;
vertical-align: middle;}
button svg {
height: 15px;
margin-right: 5px;}
<button class="primary add-student">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0" y="0" viewBox="15.6 15.6 114.7 114.7" enable-background="new 15.6 15.6 114.7 114.7" xml:space="preserve" class="plus">
<path d="M128.1 59.6c-1.5-1.5-3.4-2.3-5.5-2.3H88.6V23.5c0-2.2-0.8-4-2.3-5.5 -1.5-1.5-3.4-2.3-5.5-2.3H65.2c-2.2 0-4 0.8-5.5 2.3s-2.3 3.4-2.3 5.5v33.9H23.5c-2.2 0-4 0.8-5.5 2.3s-2.3 3.4-2.3 5.5v15.6c0 2.2 0.8 4 2.3 5.5 1.5 1.5 3.4 2.3 5.5 2.3h33.9v33.9c0 2.2 0.8 4 2.3 5.5 1.5 1.5 3.4 2.3 5.5 2.3h15.6c2.2 0 4-0.8 5.5-2.3 1.5-1.5 2.3-3.4 2.3-5.5V88.6h33.9c2.2 0 4-0.8 5.5-2.3 1.5-1.5 2.3-3.4 2.3-5.5V65.2C130.4 63 129.6 61.2 128.1 59.6z"></path>
</svg><span>Add Student</span>
</button>

Related

SVG not showing up [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 days ago.
Improve this question
I have a close button, that i want to display on the top right corner of my page.
The code of the svg is as follows
.icon {
width: 24px;
height: 24px;
/* changes to the fill do nothing */
fill: currentColor;
}
<svg class="icon">
<use xlink:href="#close" />
</svg>
<!-- some more code -->
<!-- SVG Icon Library -->
<svg style="display: none;">
<symbol id=close viewBox="0 0 24 24">
<path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"></path>
</symbol>
</svg>
The icon is not showing up on the page
The following example is with an other icon. This one works...
.icon {
width: 24px;
height: 24px;
/* changes to the fill do nothing */
fill: currentColor;
}
<svg class="icon">
<use xlink:href="#info-outline" />
</svg>
<!-- some more code -->
<!-- SVG Icon Library -->
<svg style="display: none;">
<symbol id=info-outline viewBox="0 0 24 24">
<path d="M11 17h2v-6h-2v6zm1-15C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zM11 9h2V7h-2v2z"></path>
</symbol>
</svg>
These examples are more or less the same and I'm clueless as to why that doesn't display the svg.
I tried changing the size of the svg, but the Dev-Tools show that the icon has a normal size.
Changes to the fill attribute also do nothing.
Other Svg's are working as expected and so should the close icon
If the icons are standard, well-known, not original, not designer, then you can use a Google character font.
The choice and connection of icons from Google can be viewed here
Material Icons are available in five styles and a range of
downloadable sizes and densities. The icons are based on the core
Material Design principles and metrics.
The desired icons are selected and added to the HTML by name: for example, click on the icon name info and copy the code.
Below is an example of using close and info icons. Added color change when hovering over icons.
.material-symbols-outlined {
margin: 10px;
transition: transform 0.4s ease-in-out;
}
.material-symbols-outlined:hover {
transform: scale(2);
color:red;
}
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD#48,400,0,0" />
<span class="material-symbols-outlined"> close</span>
<span class="material-symbols-outlined">info</span>
I am not sure if this will help, but the way I handle svg's is by making an image instead putting the actual svg code in the html. It simplifies having to deal with the viewBox property. Instead, I import the svg into my project, then use it in either my css or html depending what type of svg it is. Then in the css I will set the desired width and height and I am done. An example is below.
body {
margin: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
#MySQL {
width: 200px;
height: 200px;
}
<!DOCTYPE html>
<html lang="en" theme="">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Example</title>
</head>
<body>
<img src="https://svgshare.com/i/qCH.svg" alt="MySQL" id="MySQL">
</body>
</html>
It is 2023
Internet Explorer is dead.
All modern browsers support native JavaScript Web Components
(and have so for the past 5 years! since Edge switched to Chromium)
No need for oldskool <symbol> mumbo jumbo
We can write semantic HTML to display SVG icons
<svg-icon></svg-icon>
<svg-icon is="info"></svg-icon>
<svg-icon is="close"></svg-icon>
to output:
All code required:
Note! It totally does not matter when you define a Custom Element, all already created (but undefined) tags will automagically upgrade.
customElements.define("svg-icon", class extends HTMLElement{
connectedCallback(){
let size = "148px";
Object.assign( this.style , {
width : size,
height : size,
display : "inline-block",
cursor : "pointer"
});
let dpath = {
"close" : "M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z",
"info" : "M11 17h2v-6h-2v6zm1-15C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zM11 9h2V7h-2v2z"
}[ this.getAttribute("is") || "info" ];
this.innerHTML = `<svg viewBox="0 0 24 24"><path d="${dpath}"/></svg>`;
}
})
svg-icon[is="close"] {
fill: red;
}
svg-icon:hover {
fill: green;
}
<svg-icon></svg-icon>
<svg-icon is="info"></svg-icon>
<svg-icon is="close"></svg-icon>
Several issues:
ID attributes are not enclosed by quotes (obviously, most Firefox and Chromium are quite forgiving)
currentColor needs to be specified either on <symbol> or <path> level – otherwise, fill colors will fall back to black.
Double check your IDs for duplicates
.icon {
width: 24px;
height: 24px;
fill: currentColor;
}
p{
color:red
}
.green{
color:green
}
<p><svg class="icon">
<use href="#close" />
</svg>
</p>
<p class="green">
<svg class="icon">
<use href="#info-outline" />
</svg>
</p>
<!-- SVG Icon Library -->
<svg style="width:0; height:0;">
<symbol id="close" viewBox="0 0 24 24" fill="currentColor">
<path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" />
</symbol>
<symbol id="info-outline" viewBox="0 0 24 24" fill="currentColor">
<path d="M11 17h2v-6h-2v6zm1-15C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zM11 9h2V7h-2v2z" />
</symbol>
</svg>

SVG not fitting parent container, preserveAspectRatio not working as expected

I have an SVG that I expect to scale to the size of it's parent container. Let's say for argument sake the parent container is width: 10rem; height: 10rem;
What I expect is that the following:
preserveAspectRatio="xMidYMid meet" viewBox="0 0 100 100"
on the SVG would size the SVG to its parent container, and center it on the X- and Y- axis. That's not working, and I'm still trying to grok the magical workings of viewBox. For example, the smaller I make the numbers (the 2nd set of numbers), the larger the SVG is within the viewBox.
Here is a codepen:
https://codepen.io/mearleycf/pen/VxGyPZ
In the codepen I want the SVG to be centered vertically and horizontally and fill the available gray space.
Your image is half the size of the custom view window viewBox.
In order to enlarge the image in half, it is necessary to reduce the viewBox twice viewBox="0 0 50 50"
1#
.viewport {
width: 10rem;
height: 10rem;
background-color: rgba(0,0,0,.2);
<div class="viewport">
<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid meet" viewBox="-3 0 50 50">
<path d="M27.38 38.45c.3676376.0432512.6447064.3548269.6447064.725s-.2770688.6817488-.6447064.725H16.62c-.2793485.0328643-.5527292-.0976886-.702766-.3356058-.1500368-.2379172-.1500368-.5408712 0-.7787884.1500368-.2379172.4234175-.3684701.702766-.3356058h10.76z"/>
<path d="M22 20.32l7-8.08H15l7 8.08zm5.77 2.59l4.17-7.76-1.44-2.41-7.28 8.38 4.55 1.79zM40 30.48c1.1964325-3.1635471 1.8718678-6.5001977 2-9.88l-4.4-2.22v8.27c.222793 1.5584681 1.0946906 2.9498712 2.4 3.83zm-11.26-6.31c-.1278873.2340796-.3732635.3797717-.64.38-.0856249.0190035-.1743751.0190035-.26 0L22 22.2l-5.84 2.3c-.0855499.0196756-.1744501.0196756-.26 0-.2643693.0005027-.5071244-.145921-.63-.38l-1.67-3.04v8.12h16.79v-8.1l-1.65 3.07zM6.39 26.59v-8.2L2 20.6c.13283876 3.3792388.80812272 6.7151415 2 9.88 1.31972827-.8919415 2.19075519-2.3096381 2.39-3.89zM42.06 19V2.08c.000044-.33854901-.271495-.61453953-.61-.62H2.57c-.16352967-.00002198-.32022048.06561659-.43490953.18218579C2.02040143 1.75875498 1.95731918 1.9164923 1.96 2.08L1.95991792 19 10.74 14.58l2.05-3.45v-.05a.6199991.6199991 0 0 1 .14-.14l.09-.06c.0606197-.0379407.1289512-.0618568.2-.07h17.53c.0710488.0081432.1393803.0320593.2.07l.09.06a.6199991.6199991 0 0 1 .14.14v.05l2.05 3.45L42.06 19zm-30-3.85l4.17 7.76 4.55-1.79-7.28-8.38-1.44 2.41zm.1 14.78V18.66a.57999937.57999937 0 0 1 0-.19l-1.23-2.37-3.09 1.56v9c-.23358787 2.140913-1.43965798 4.0551344-3.27 5.19 3.28318525 7.6277175 9.4797039 13.6262068 17.21 16.66.147458.0600295.312542.0600295.46 0 7.7209585-3.0462892 13.9080563-9.0462264 17.19-16.67-1.8174849-1.1243263-3.0217854-3.0173247-3.27-5.14v-9l-3.09-1.6-1.24 2.31v11.52c.0000375.3992947-.3207428.7245302-.72.73H12.88c-.3992572-.0054698-.7200375-.3307053-.72-.73zm9.12 19.95C9.07046721 45.052873.91252114 33.4138361.54 20.29a1.00000007 1.00000007 0 0 1 0-.17V2.08C.52887155.94612822 1.43619307.01645888 2.57 0h38.88c1.1181022.03256431 2.0059041.95143932 2 2.07v18.05a.99999966.99999966 0 0 1 0 .17c-.3740569 13.1119454-8.517206 24.7427688-20.71 29.58-.2373877.0854445-.4877039.129419-.74.13-.244887-.0010737-.4880019-.0415928-.72-.12z"/>
</svg>
</div>
2#
The first variant of the solution fulfills the conditions of the question, but is not adaptive.
In order for svg to change its size along with changing the size of the parent container, you must specify its width and height in percent
.viewport {
width:25%;
height:25%;
}
#rect {
fill: rgba(0,0,0,.2);
}
<div class="viewport">
<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMinYMin meet" viewBox="-6 0 50 50">
<rect id="rect" width="100%" height="100%" />
<path d="M27.38 38.45c.3676376.0432512.6447064.3548269.6447064.725s-.2770688.6817488-.6447064.725H16.62c-.2793485.0328643-.5527292-.0976886-.702766-.3356058-.1500368-.2379172-.1500368-.5408712 0-.7787884.1500368-.2379172.4234175-.3684701.702766-.3356058h10.76z"/>
<path d="M22 20.32l7-8.08H15l7 8.08zm5.77 2.59l4.17-7.76-1.44-2.41-7.28 8.38 4.55 1.79zM40 30.48c1.1964325-3.1635471 1.8718678-6.5001977 2-9.88l-4.4-2.22v8.27c.222793 1.5584681 1.0946906 2.9498712 2.4 3.83zm-11.26-6.31c-.1278873.2340796-.3732635.3797717-.64.38-.0856249.0190035-.1743751.0190035-.26 0L22 22.2l-5.84 2.3c-.0855499.0196756-.1744501.0196756-.26 0-.2643693.0005027-.5071244-.145921-.63-.38l-1.67-3.04v8.12h16.79v-8.1l-1.65 3.07zM6.39 26.59v-8.2L2 20.6c.13283876 3.3792388.80812272 6.7151415 2 9.88 1.31972827-.8919415 2.19075519-2.3096381 2.39-3.89zM42.06 19V2.08c.000044-.33854901-.271495-.61453953-.61-.62H2.57c-.16352967-.00002198-.32022048.06561659-.43490953.18218579C2.02040143 1.75875498 1.95731918 1.9164923 1.96 2.08L1.95991792 19 10.74 14.58l2.05-3.45v-.05a.6199991.6199991 0 0 1 .14-.14l.09-.06c.0606197-.0379407.1289512-.0618568.2-.07h17.53c.0710488.0081432.1393803.0320593.2.07l.09.06a.6199991.6199991 0 0 1 .14.14v.05l2.05 3.45L42.06 19zm-30-3.85l4.17 7.76 4.55-1.79-7.28-8.38-1.44 2.41zm.1 14.78V18.66a.57999937.57999937 0 0 1 0-.19l-1.23-2.37-3.09 1.56v9c-.23358787 2.140913-1.43965798 4.0551344-3.27 5.19 3.28318525 7.6277175 9.4797039 13.6262068 17.21 16.66.147458.0600295.312542.0600295.46 0 7.7209585-3.0462892 13.9080563-9.0462264 17.19-16.67-1.8174849-1.1243263-3.0217854-3.0173247-3.27-5.14v-9l-3.09-1.6-1.24 2.31v11.52c.0000375.3992947-.3207428.7245302-.72.73H12.88c-.3992572-.0054698-.7200375-.3307053-.72-.73zm9.12 19.95C9.07046721 45.052873.91252114 33.4138361.54 20.29a1.00000007 1.00000007 0 0 1 0-.17V2.08C.52887155.94612822 1.43619307.01645888 2.57 0h38.88c1.1181022.03256431 2.0059041.95143932 2 2.07v18.05a.99999966.99999966 0 0 1 0 .17c-.3740569 13.1119454-8.517206 24.7427688-20.71 29.58-.2373877.0854445-.4877039.129419-.74.13-.244887-.0010737-.4880019-.0415928-.72-.12z"/>
</svg>
</div>
Now increasing, decreasing the percentage of width and height of the parent container .viewport will also exactly change the size ofSVG
Changing viewBox to viewBox="-3 0 50 50" fix it. I think you can not get equal width and height to fit svg to square div because it needs to keep proportions.

SVG doesn't display on Firefox but in Chrome and Edge works fine

I have a little problem, I'm used to use SVG icons by this way:
span{
width:30px;
height:30px;
}
span svg{
width: inherit;
height: inherit;
display:block;
fill: red;
}
<svg style="display: none;">
<symbol id="arrow" viewBox="0 0 250 250">
<path d="M70.9 245.5c-1.7 1.7-3.8 2.5-6.2 2.5s-4.5-.8-6.2-2.5c-3.4-3.4-3.4-8.9 0-12.3L166.8 125 58.6 16.8c-3.4-3.4-3.4-8.9 0-12.3 3.4-3.4 8.9-3.4 12.3 0l114.4 114.4c3.4 3.4 3.4 8.9 0 12.3L70.9 245.5z"/>
</symbol>
</svg>
<span>
<svg class="icon" viewBox="0 0 250 250">
<use xlink:href="#arrow"></use>
</svg>
</span>
Recently xlink:href attribute has been deprecated for SVG2 so I decided to remove all xlink:href from the project leaving href MDN Doc
As you can see on MDN Docs, the recommendation is to use href instead of xlink:href and it works fine on Chrome and Edge but no on Firefox.
This is a link to the project Link, if you open the website with Chrome or Edge you will see a small icons on top navigation, but no on Firefox.
¿Can someone give me a solution?
P.D: Sorry about my english.
href support will arrive in Firefox 51.
Firefox 51 will be released on 24 January 2017, but you can try a nightly right now if you want to test it out.
Prior to this you'll just need to stick with xlink:href (or both) if you want Firefox compatibility.

SVG Oversized on Load

I have a simple search icon as an SVG I'm using, but for some reason, when I load my webpage, it is huge despite a 24x24 lock in the CSS and in the styling of the SVG itself.
It spreads out and takes up the whole page until everything is done loading, then it snaps to the normal 24x24 size. It looks absolutely ridiculous and I know I have to be doing something wrong. Any ideas?
SVG:
<svg style="position: absolute; width: 0; height: 0;" width="0" height="0" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<symbol id="icon-search" class="icon" viewBox="0 0 24 24">
<title>search</title>
<circle class="st0" cx="9.3" cy="9.2" r="8.6" />
<line class="st1" x1="15.3" y1="15.4" x2="23.3" y2="23.4" />
</symbol>
</defs>
HTML:
<div class="searchContainer">
<div class="search">
<input class="image" type="image" src="images/search.svg"><input class="text" type="text" onfocus="if(this.value == 'Search') { this.value = ''; }" value="Search" onblur="if (this.value == '') { this.value = 'Search'; }">
</div><!-- /search -->
</div><!-- /searchContainer -->
CSS:
input.image{
fill: black;
width: 24px;
height: 24px;
border: 0;
padding-top: 9px;
text-align: right;
}
Here is what I'm Seeing on Load.
Note that the other icons are also SVGs, but they are done in a single file with the method I couldn't use with the input for the search.
<svg><use xlink></use></svg>
Any help appreciated. Thank you!
You can solve this by adding the width and height attributes directly to the SVG. For example, your SVG might look something like this:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 225 225" width="20" height="20">
<title>Search</title>
<path fill="#fff" d="M225 202v8c-2.7 7.3-7.6 12.4-15 15h-8c-7.3-1.2-12.4-5.7-17.3-10.9-6.6-7-13.6-13.7-20.4-20.6-11.5-11.6-22.9-23.2-34.3-34.7-18 10.2-36.7 14.6-56.6 11.2-34.8-5.9-57.9-25.9-69.3-59.2C2 105.2 1.3 99 0 93V78c.3-.8.7-1.5.8-2.3C6.1 38.8 27 15 62.1 3.4 67.2 1.7 72.7 1.1 78 0h15c3.6.7 7.1 1.3 10.7 2C140 8.7 170 44.2 171.1 81.2c.5 17.2-3.3 33.3-12.5 49.2 1.3 1 3 1.9 4.2 3.2 17.1 17 34.1 34.2 51.3 51.2 5.1 4.9 9.7 9.9 10.9 17.2zM85.1 146.9c33 .5 61.5-27.3 61.9-60.4.4-33.7-26.7-61.5-60.6-62.2-33.3-.7-61.5 26.8-62.1 60.6-.6 33.3 27 61.5 60.8 62z"/>
</svg>
Note where it says width="20" height="20" specifically. That will limit the SVG size when the image loads. Then you can adjust the height and width using CSS as needed.
Put the SVG IMG element inside a div and then size the div and the img appropriately...
<div id="logo">
<img id="logo_img" src="assets/images/logo.svg">
</div>
#logo {
display: block;
height: 50px;
}
#logo_img {
height: 50px;
width: 200px;
}
Load the SVG and style inline. If you put the tags above the tags it will remove the giant stutter on page load.
If you can load your svg inside an <img> tag then set the size of the img directly
<img src="badge.svg" width="200">
My solution is to have the opacity of the SVG element set to 0 and then set it to 1 after loading.
1. Add the opacity: 0; to the element or its parent in your CSS.
2. Optionally add a transition, like transition: 0.5s opacity;
3. Create a new class, let's say "loaded", with the opacity: 1;
4. In JavaScript add a line in the load event that adds the "loaded" class to the SVG element or its parent.
Even better solution...
Add style="display:none;" attribute inline to img tag(s).
Use jQuery to .show() img once page is fully loaded.
$( window ).load(function() {
$('.container img').show();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<div class="container">
<img src="https://www.zdmdesigns.com/images/zdm-logo.svg" style="display:none;">
</div>
You will need to identify your width and height on the html dom.
Also, try using the tags below
<object data="your_svg_path" width="57" height="57" type="image/svg+xml">
</object>
Not the answer to the original question, but maybe it helps someone.
If you are using a CMS and FontAwesome as JS you maybe need to disable FA in edit mode so it does not replace the tags. Without the FA-Script loaded the stays in the content, not the .

SVG's not inheriting values from parent

So this seems to be a bug that just cropped up in Chrome today (and Firefox apparently).
I have an SVG wrapped inside a span (I've tried div's and object tags as well, it doesn't seem to matter), and that span has a specified height and width. Yesterday, the child element would size itself appropriately to the full dimensions of it's parent, as every other html element does. However, now, that SVG element is not getting the inherited size from its parent, and is sizing itself based off the actual size of the SVG.
Check out the fiddle here: http://jsfiddle.net/theandybob/4LHeB/
The CSS:
.icon-small {
width: 32px;
height: 32px;
position: relative;
display: inline-block;
}
And the Code:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<symbol id="run-import" viewBox="0 0 48 48">
<path fill="#4B4B4B" d="M24,0c4.4,0,8.4,1.1,12,3.2s6.6,5.1,8.7,8.7c2.1,3.7,3.2,7.7,3.2,12s-1.1,8.4-3.2,12 c-2.1,3.7-5.1,6.6-8.7,8.7c-3.7,2.1-7.7,3.2-12,3.2c-4.4,0-8.4-1.1-12-3.2c-3.7-2.1-6.6-5.1-8.7-8.7C1.1,32.4,0,28.4,0,24 s1.1-8.4,3.2-12S8.3,5.4,12,3.2S19.6,0,24,0z M36,25.7c0.7-0.4,1-0.9,1-1.7c0-0.8-0.3-1.3-1-1.7l-17-10c-0.6-0.4-1.3-0.4-2,0 c-0.7,0.4-1,1-1,1.8v20c0,0.8,0.3,1.4,1,1.8c0.3,0.2,0.7,0.3,1,0.3c0.4,0,0.7-0.1,1-0.3L36,25.7z"></path>
</symbol>
</svg>
<span class="icon-small">
<svg><use xlink:href="#run-import"></use></svg>
</span>
Now, this happens in Chrome (both on Windows and Mac), and Firefox, but not IE or Safari. Ideas on how to fix the issue, or where it came up from?
The only workaround I have now is to specifically set the svg size to inherit from it's parent.
Also, throwing the version numbers out there:
1. Chrome: Version 36.0.1985.125 m
2. Firefox: 30.0
You need height and width on the <svg> element which you can set using CSS if you wish but which I've set using attributes.
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="0" height="0">
<symbol id="run-import" viewBox="0 0 48 48">
<path fill="#4B4B4B" d="M24,0c4.4,0,8.4,1.1,12,3.2s6.6,5.1,8.7,8.7c2.1,3.7,3.2,7.7,3.2,12s-1.1,8.4-3.2,12 c-2.1,3.7-5.1,6.6-8.7,8.7c-3.7,2.1-7.7,3.2-12,3.2c-4.4,0-8.4-1.1-12-3.2c-3.7-2.1-6.6-5.1-8.7-8.7C1.1,32.4,0,28.4,0,24 s1.1-8.4,3.2-12S8.3,5.4,12,3.2S19.6,0,24,0z M36,25.7c0.7-0.4,1-0.9,1-1.7c0-0.8-0.3-1.3-1-1.7l-17-10c-0.6-0.4-1.3-0.4-2,0 c-0.7,0.4-1,1-1,1.8v20c0,0.8,0.3,1.4,1,1.8c0.3,0.2,0.7,0.3,1,0.3c0.4,0,0.7-0.1,1-0.3L36,25.7z"></path>
</symbol>
</svg>
<span class="icon-small">
<svg width="100%" height="100%"><use xlink:href="#run-import"></use></svg>
</span>