How to set a rotation point on a nested SVG Element - html
Recently, I decided to experiment and learn about CSS Transforms. Now, I decided to try and make a common mobile button using SVG and a few transforms.
What I'm trying to do is to make the mobile button rotate 90 degrees with a transform origin on the very center of the element.
Here is my code:
.mobileNav {
display: block;
transition: .5s;
}
.mobileNav:hover {
transform: rotate(90deg);
transform-origin: 50% 50%;
/*This is where the problem lies. How do I set the origin to the center of .mobileNav?? */
}
ul {
float: right;
margin: 15px 50px 0px 0px;
}
li {
display: inline-block;
transition: .5s;
}
<ul class="mobileNav">
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />
Sorry, your browser does not support inline SVG.
</svg>
</li>
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />
Sorry, your browser does not support inline SVG.
</svg>
</li>
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />
Sorry, your browser does not support inline SVG.
</svg>
</li>
</ul>
GOAL: To set the transform origin to the center of .mobileNav.
PROBLEM: I am unable to achieve this.
BROWSER: My browser is Firefox 44.0.2
ul has defaut padding or margin that needs a reset.
li and svg could be reset to inline-block.
Lets draw a border for debug to see where things stand.
vertical-aign + line-height will help to define an height to ul and will set childs at vertical middle.
body {
margin-top:50px;/* snippet wants this */
}
.mobileNav {
display: block;
transition: .5s;
border: solid;
padding: 0
}
.mobileNav:hover {
transform: rotate(90deg);
}
ul {
float: right;
margin: 15px 50px 0px 0px;
line-height: 1em;
}
li,
svg {
display: inline-block;
vertical-align: middle;
transition: .5s;
}
<ul class="mobileNav">
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />Sorry, your browser does not support inline SVG.
</svg>
</li>
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />Sorry, your browser does not support inline SVG.
</svg>
</li>
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />Sorry, your browser does not support inline SVG.
</svg>
</li>
</ul>
Your problem is the default padding. For added effect, you can also set the SVG and li's to not be display inline or inline-block. Then float them so the align vertically. That should make it not as janky.
body {padding: 3em;}
.mobileNav {
display: block;
transition: .5s;
padding: 0;
}
.mobileNav:hover {
transform: rotate(90deg);
transform-origin: 50% 50%;
/*This is where the problem lies. How do I set the origin to the center of .mobileNav?? */
}
ul {
float: right;
margin: 15px 50px 0px 0px;
}
li {
display: inline-block;
transition: .5s;
}
.mobileNav svg, .mobileNav li {
display:block;
float:left;
}
<ul class="mobileNav">
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />
Sorry, your browser does not support inline SVG.
</svg>
</li>
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />
Sorry, your browser does not support inline SVG.
</svg>
</li>
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />
Sorry, your browser does not support inline SVG.
</svg>
</li>
</ul>
Related
How does the `a` tag behave?
Could you explain how the a tag behaves in this example? Why is it so small? a { border: 1px solid currentColor; } <li> <a href="https://facebook.com/starbucks"> <svg aria-hidden="true" class="valign-middle absoluteCenter" focusable="false" preserveAspectRatio="xMidYMid meet"> <path></path> <circle class="sb-icon-hover" cx="50%" cy="50%" fill="transparent" r="75%"></circle> </svg> </a> </li> Also, could you explain, how to fix it? And how to center it inside the block? Thank you!
The anchor element (<a>) is by default an inline element. It will have the height of the font (example 1). So, making a border around it will display the height of the font. If you set the display of the <a> to inline-block or block (example 2 and 3) the element will "contain" the child elements (except if you limit the height...). With either one you can set properties like border, background, padding, margin etc. svg { display: inline; /*default*/ height: 2em; vertical-align: bottom; } a { border: 1px solid currentColor; } ul li:nth-child(1) a { display: inline; /*default*/ } ul li:nth-child(2) a { display: inline-block; } ul li:nth-child(3) a { display: block; } li { margin: .1em; } <ul> <li> <a href="https://facebook.com/starbucks">default <svg viewBox="0 0 100 100"> <circle cx="50%" cy="50%" fill="red" r="50%"/> </svg> </a> </li> <li> <a href="https://facebook.com/starbucks">inline-block <svg viewBox="0 0 100 100"> <circle cx="50%" cy="50%" fill="red" r="50%"/> </svg> </a> </li> <li> <a href="https://facebook.com/starbucks">block <svg viewBox="0 0 100 100"> <circle cx="50%" cy="50%" fill="red" r="50%"/> </svg> </a> </li> </ul>
How can I center scaled radio button icons in their DIV?
The "logo" appearing as a yellow SVG circle below can be scaled by adjusting the height ratio (line indicated by <==== (1) in the code), enabling tuning without modifying the SVG itself. But even though .left_center_myicon is mostly duplicated in .right_center_myicon, the same tuning in <==== (2) does not affect the radio button icons. How can I center scaled radio button icons in their DIV? I'm using here inline SVGs as even changing them to be linked (from <svg> to <img src="xyz.svg"> is itself a brittle and subtle change. If you see that difficulty, please switch to linked SVGs in your answer. Update I'd like the radio buttons to be vertically centered in their div, while that div is itself vertically centered and right justified in the header. Ideally, I'd also like to be able to adjust the scale of the SVG radio button icons from the style file (although I'm starting to wonder whether doing so might be going against the grain of established custom—in other words, I'm wondering if perhaps designers end up editing the SVG files rather than manipulating the scale of the SVGs from CSS). .header { width: 100%; height: 300px; background-color: #ddd; margin: 5px; align-items:center; display: block; text-align: center; } .left_center_myicon { margin: 0 auto; background-color: #bbb; float: left; height: 70%; /* <==== (1) */ position: relative; top: 50%; left: 0; transform: translate(0%, -50%); } .right_center_myicon { background-color: #ccc; margin: 0 auto; float: right; height: 70%; /* <==== (2) */ position: relative; top: 50%; left: 0; transform: translate(0%, -50%); vertical-align: middle; } svg { stroke:black; stroke-width:5; opacity:0.5; vertical-align: middle; } <div class="header"> <a href="index.html"> <img class="left_center_myicon" src="svg/logo.svg"/> </a> <div class="right_center_myicon"> <label class="myLabel"> <input type="radio" name="radioGroup" class="myradioG" checked> <svg width="100" height="100" viewBox="0 0 100 100"> <circle cx="50" cy="50" r="30" style="fill:blue;" /> </svg> </label> <label class="inline-radio"> <input type="radio" name="radioGroup" class="myradioG"> <svg width="100" height="100" viewBox="0 0 100 100"> <rect x="20" y="20" rx="15" ry="15" width="60" height="60" style="fill:red;" /> </svg> </label> </div> </div> The content of logo.svg is: <?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="160" height="120" viewBox="0 0 160 120" version="1.1"> <g> <circle cx="80" cy="60" r="50" fill="yellow" stroke="blue" stroke-width="10" /> </g> </svg>
When in doubt, flexbox all the things. And add some wrappers... and a spacer. I find CSS float maddening to work with, so I avoid it like the plague. And to answer your other question, whenever possible I include my svgs inline so the inner components can still be targeted/styled with CSS. This approach should work with either though. I tried making a fiddle but couldn't get even the simplest code to work or display anything, so I'm not sure if that's me or them.... Works great locally in my browser though. https://imgur.com/AWrWK8Z I made 2 additions, a middle spacer element set to flex grow so it takes up all the available space it can, pushing the other elements far to the right/left. And wrappers around the input/label pairs (and the lone left guy). I used flex on both the header container and the right and left child containers, to simplify vertical centering. .header { width: 100%; height: 300px; display: flex; align-items: center; background-color: #ddd; } .spacer { flex: 1 0 auto; background: rgba(200,200,200,1); } .left { background-color: #bbb; } .right { background-color: #ccc; } .wrapper { display: flex; height: 70%; align-items: center; outline: 1px solid blue; } .wrapper > div { flex: 1 1 auto; outline: 1px solid black; } <div class="header"> <div class="left wrapper"> <div> <a> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="160" height="120" viewBox="0 0 160 120" version="1.1"> <g> <circle cx="80" cy="60" r="50" fill="yellow" stroke="blue" stroke-width="10" /> </g> </svg> </a> </div> </div> <div class="spacer"></div> <div class="right wrapper"> <div> <label class="myLabel"> <input type="radio" name="radioGroup" class="myradioG" checked> <svg width="100" height="100" viewBox="0 0 100 100"> <circle cx="50" cy="50" r="30" style="fill:blue;" /> </svg> </label> </div> <div> <label class="inline-radio"> <input type="radio" name="radioGroup" class="myradioG"> <svg width="100" height="100" viewBox="0 0 100 100"> <rect x="20" y="20" rx="15" ry="15" width="60" height="60" style="fill:red;" /> </svg> </label> </div> </div> </div>
How can I align svg circle in the middle of the div?
I need to make a circle emulating the button for closing the window in the Mac OS. But when I try to move it lower, svg's border cuts it off. How can I move the border to place the circle directly in the middle of the panel (vertically)? JSFiddle: https://jsfiddle.net/sm6r0kvn/2/ <div class="panel"> <svg viewbox="0 0 20 17" width="20" heigth="50"><circle r="7" cx="14" cy="9.5" fill="#fc615e"/></svg> </div>
You can set your viewbox like <svg viewbox="0 0 20 20" width="20" heigth="20"> and then set cx and cy 50%. If you want to center it in the panel vertically just make it a flexbox and add align-items: center - see demo below: .block { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); max-width: 550px; min-width: 480px; width: 80vw; height: 200px; background: black; border-radius: 10px 10px 5px 5px; } .panel { background-color: #e0e0e0; border-radius: 5px 5px 0 0; display: flex; /* added */ align-items: center; /* added */ } .text { color: white; padding: 5px; } <div class="block"> <div class="panel"> <svg viewbox="0 0 20 20" width="20" heigth="20"> <circle r="7" cx="50%" cy="50%" fill="#fc615e"/> </svg> </div> <div class="text"> Text here </div> </div>
This is because you are drawing your cicrcle outside of the svg viewbox. You can either use CSS to move whole svg box or make it larger svg { border: 1px blue solid; } .panel.moved { margin-left: 100px; } <div class="panel"> <svg viewbox="0 0 20 20" width="200" heigth="200"> <circle r="10" cx="10" cy="10" fill="#fc615e"/> </svg> </div> <div class="panel"> <svg viewbox="0 0 20 20" width="200" heigth="200"> <circle r="10" cx="20" cy="10" fill="#fc615e"/> </svg> </div> <div class="panel"> <svg viewbox="0 0 30 20" width="300" heigth="200"> <circle r="10" cx="20" cy="10" fill="#fc615e"/> </svg> </div> <div class="panel moved"> <svg viewbox="0 0 20 20" width="200" heigth="200"> <circle r="10" cx="10" cy="10" fill="#fc615e"/> </svg> </div>
How to change position of svg on hover with a transition delay
I'm trying to move svg icons in my navbar to the left on hovering, which I'm able to do so, but I need the element to move smoothly through something like this transition : all .5s; The issue is that svg tag doesn't accept transition property in css, so I tried to use the transition on the container, but that doesn't work, it just move instantly without transition effect. HTML : <div id="sidenav-icon-section"> <li> <a href="/"> <img src="/assets/images/home.svg" alt="home" onload="SVGInject(this)"> </a> </li> </div> I use the SVGInject library to transform my svg code in the browser, which results to this : <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" width="64px" height="64px" viewBox="0 0 64 64" enable-background="new 0 0 64 64" xml:space="preserve" data-inject-url="http://localhost:4200/assets/images/home.svg" _ngcontent-c1=""> <polygon fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" points="32,3 2,33 11,33 11,63 23,63 23,47 39,47 39,63 51,63 51,33 62,33 "></polygon></svg> Also I have another svg icon that has a path tag instead of polygon CSS : #sidenav-icon-section { top: 25%; position: relative; li { position: relative; transition: all .5s; &:hover svg { left: 7%; } } } I tried applying the transition to and the "left" attribute to path and polygon elements but nothing happens at that point, they don't even move.
You are trying to set the attribute left on an element which position is static. Try a negative margin instead. Also you are applying the transition to the wrong element. svg { transition: margin-left .5s } li:hover svg { margin-left: -7px; } <ul id="sidenav-icon-section"> <li class="item"> <a href="/"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" width="64px" height="64px" viewBox="0 0 64 64" enable-background="new 0 0 64 64" xml:space="preserve" data-inject-url="http://localhost:4200/assets/images/home.svg" _ngcontent-c1=""> <polygon fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" points="32,3 2,33 11,33 11,63 23,63 23,47 39,47 39,63 51,63 51,33 62,33 "></polygon></svg> </a> </li> </ul> the scss equivalent: li { svg { transition: margin-left .5s; } &:hover svg { margin-left: -7px; } }
SVG Fill Animation doesn't work on Firefox and Edge
I have a simple animation where an SVG fills on mouse over. It is working fine on Chrome, but I've found that it's doesn't workg on Firefox or Edge. I've tried few different approaches, but nothing seems to help. I'm new to SVG and I guess I'm missing something? What is the proper way to achieve what I'm trying to do? Here is the code: svg#bogeLogo { display: block; left: 50%; position: absolute; top: 50%; transform: translate(-50%,-50%); } svg#bogeLogo #bogePath { fill: transparent; stroke: red; stroke-width: 8; } svg#bogeLogo #bogeFinal { fill: blue; } svg#bogeLogo #bogeClip rect { transition: all 1.4s ease-out !important; width: 0; } svg#bogeLogo:hover #bogeClip rect { width: 100%; } <svg id="bogeLogo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 2551.2 2551.2" style="enable-background:new 0 0 100 100;" xml:space="preserve"> <defs> <path id="bogePath" d="M1263.5,1239.5l0-1l0.8-1194.9l-60.3,0l-0.6,1195.9l-1146.6,0.2v60.3l1146.6-0.5v1195h59l1-1195 l1231.9,0.5l0-60.3L1263.5,1239.5z M779.6,1037c98.3-37.9,134.5-130.5,138.1-140c6.8-18.3,31.3-87,1.9-161.1 c-20.6-52-58.4-82.8-74.8-95.9c-23.2-18.5-45.4-27.8-61.3-34.5c13.2-6.5,52.6-26.9,76.7-90.2c26-68.5-0.8-128.3-7.7-143.8 c-25.5-57.3-74.1-84.5-95-96.9c-31.8-19-83.7-25.5-104.2-26.3L410.2,248v3.2l-1.1,800.3v1.1l293.7-0.2 C721.3,1051.7,748.9,1048.8,779.6,1037z M570.6,394.5c46.8-9.2,80.5-1.6,97.8,3.8c19.2,6.1,27.6,12.5,32.6,17.3 c22.3,21.1,22.8,51.6,23,61.4c0.2,9.5,0.7,37.9-19.2,61.4c-18.5,21.9-43.5,28.8-65.2,30.7c-31.6,2.7-51.9,2.2-69-1.9V394.5z M570.6,908.5V701.4c33.3-3.2,60.9-2.9,80.5-1.9c39.3,2,59.3,3.2,80.5,15.3c7,4,29.8,17.4,44.1,46c5.2,10.5,15.6,35.6,9.6,67.1 c-2.2,11.7-9.7,39.6-34.5,59.5c-11,8.7-25.4,16-63.3,21.1C660.3,912.2,620.2,914.9,570.6,908.5z M1835.5,1052.5 c218.7,0,395-184.3,395-403s-177.3-407-396-407s-396,188.3-396,407S1616.8,1052.5,1835.5,1052.5z M1835,390.5 c131.3,0,237.8,116.2,237.8,259.5S1966.3,909.5,1835,909.5S1597.2,793.3,1597.2,650S1703.7,390.5,1835,390.5z M636.5,1879.5v1l1,129 v0.1c73,0.1,142.9,0.3,216,0.4c-5.4,14.1-15,34.1-31.6,54.7c-5.9,7.2-35.7,43.1-89.4,63.7c-58.3,22.4-109.4,13.3-136.9,8.1 c-54.1-10.3-90.3-33.6-98.9-39.3c-39-25.9-60.5-55.8-71.8-71.8c-14.1-20-35.1-50.4-44.7-96.2c-2.4-11.6-10.4-54.2,2.7-107.1 c3.5-14.3,14.4-52.5,44.7-92.2c9.3-12.2,39.6-49.6,93.5-75.9c15.2-7.4,47.4-21.4,90.8-25.7c7.7-0.8,40-3.7,81.3,4.1 c19.2,3.6,46.7,9,77.2,25.7c14.7,8,31,19.8,63.7,43.4c8.8,6.3,15.7,12.5,20.5,16l90-106c-15.9-18.7-35.7-40.2-71-63 c-54-35-103.7-45.6-141.8-53.3c-31.3-6.3-86.6-17-158.1-6.3c-59.3,8.9-105.3,28.7-134.6,44.3c-49.5,26.2-82,56.1-95.8,69.6 c-39.5,38.6-60.6,75.2-65,83.1c-4.7,8.2-27.1,48.6-39.8,107.5c-2.3,10.9-9.1,44.7-9,89.4c0,22.3,0.4,59.9,13.6,106.6 c10.1,35.8,23.2,61,32.5,78.6c11,20.9,29,54.4,62.3,90.3c39,42.1,79.9,66.8,106.6,80.4c46.4,23.6,85.8,31.6,109.3,36.1 c25.3,4.9,72.3,11.8,131,6.3c27.9-2.6,61.2-6,102.1-21.7c14.8-5.7,58.3-23.6,103-63.2c42.8-37.9,65.1-76.5,79.5-102.1 c12.4-21.9,31.2-55.8,42.5-104.8c10.8-46.8,9.9-87,7.3-113.9L636.5,1879.5z M1019,1874.6c0,0.3,0.1,0.6,0.1,0.9l1.4,0L1019,1874.6z M1753.3,1919.6l291.8,1.1v-1.1l-1.1-142.2l-285.5,1.1h-1.1l1-137.9h1l304.6-3.3h1.1v-151.7h-464.6v2.1l-0.5,794l0,0.4h470.4v-146.4 h-317.1V1919.6z"/> <clipPath id="bogeClip"> <rect x="0" y="0" height="100%" width="100%"/> </clipPath> </defs> <use xlink:href="#bogePath"/> <path id="bogeFinal" clip-path="url(#bogeClip)" d="M1263.5,1239.5l0-1l0.8-1194.9l-60.3,0l-0.6,1195.9l-1146.6,0.2v60.3l1146.6-0.5v1195h59l1-1195 l1231.9,0.5l0-60.3L1263.5,1239.5z M779.6,1037c98.3-37.9,134.5-130.5,138.1-140c6.8-18.3,31.3-87,1.9-161.1 c-20.6-52-58.4-82.8-74.8-95.9c-23.2-18.5-45.4-27.8-61.3-34.5c13.2-6.5,52.6-26.9,76.7-90.2c26-68.5-0.8-128.3-7.7-143.8 c-25.5-57.3-74.1-84.5-95-96.9c-31.8-19-83.7-25.5-104.2-26.3L410.2,248v3.2l-1.1,800.3v1.1l293.7-0.2 C721.3,1051.7,748.9,1048.8,779.6,1037z M570.6,394.5c46.8-9.2,80.5-1.6,97.8,3.8c19.2,6.1,27.6,12.5,32.6,17.3 c22.3,21.1,22.8,51.6,23,61.4c0.2,9.5,0.7,37.9-19.2,61.4c-18.5,21.9-43.5,28.8-65.2,30.7c-31.6,2.7-51.9,2.2-69-1.9V394.5z M570.6,908.5V701.4c33.3-3.2,60.9-2.9,80.5-1.9c39.3,2,59.3,3.2,80.5,15.3c7,4,29.8,17.4,44.1,46c5.2,10.5,15.6,35.6,9.6,67.1 c-2.2,11.7-9.7,39.6-34.5,59.5c-11,8.7-25.4,16-63.3,21.1C660.3,912.2,620.2,914.9,570.6,908.5z M1835.5,1052.5 c218.7,0,395-184.3,395-403s-177.3-407-396-407s-396,188.3-396,407S1616.8,1052.5,1835.5,1052.5z M1835,390.5 c131.3,0,237.8,116.2,237.8,259.5S1966.3,909.5,1835,909.5S1597.2,793.3,1597.2,650S1703.7,390.5,1835,390.5z M636.5,1879.5v1l1,129 v0.1c73,0.1,142.9,0.3,216,0.4c-5.4,14.1-15,34.1-31.6,54.7c-5.9,7.2-35.7,43.1-89.4,63.7c-58.3,22.4-109.4,13.3-136.9,8.1 c-54.1-10.3-90.3-33.6-98.9-39.3c-39-25.9-60.5-55.8-71.8-71.8c-14.1-20-35.1-50.4-44.7-96.2c-2.4-11.6-10.4-54.2,2.7-107.1 c3.5-14.3,14.4-52.5,44.7-92.2c9.3-12.2,39.6-49.6,93.5-75.9c15.2-7.4,47.4-21.4,90.8-25.7c7.7-0.8,40-3.7,81.3,4.1 c19.2,3.6,46.7,9,77.2,25.7c14.7,8,31,19.8,63.7,43.4c8.8,6.3,15.7,12.5,20.5,16l90-106c-15.9-18.7-35.7-40.2-71-63 c-54-35-103.7-45.6-141.8-53.3c-31.3-6.3-86.6-17-158.1-6.3c-59.3,8.9-105.3,28.7-134.6,44.3c-49.5,26.2-82,56.1-95.8,69.6 c-39.5,38.6-60.6,75.2-65,83.1c-4.7,8.2-27.1,48.6-39.8,107.5c-2.3,10.9-9.1,44.7-9,89.4c0,22.3,0.4,59.9,13.6,106.6 c10.1,35.8,23.2,61,32.5,78.6c11,20.9,29,54.4,62.3,90.3c39,42.1,79.9,66.8,106.6,80.4c46.4,23.6,85.8,31.6,109.3,36.1 c25.3,4.9,72.3,11.8,131,6.3c27.9-2.6,61.2-6,102.1-21.7c14.8-5.7,58.3-23.6,103-63.2c42.8-37.9,65.1-76.5,79.5-102.1 c12.4-21.9,31.2-55.8,42.5-104.8c10.8-46.8,9.9-87,7.3-113.9L636.5,1879.5z M1019,1874.6c0,0.3,0.1,0.6,0.1,0.9l1.4,0L1019,1874.6z M1753.3,1919.6l291.8,1.1v-1.1l-1.1-142.2l-285.5,1.1h-1.1l1-137.9h1l304.6-3.3h1.1v-151.7h-464.6v2.1l-0.5,794l0,0.4h470.4v-146.4 h-317.1V1919.6z"></path> </svg>
Modifying geometric attributes, such as width, is a new thing in SVG 2. Only Chrome has implemented that so far. You will need to use a different method to animate your <rect>. For example, you could move it horizontally using a transform, instead of changing its width. Update It looks like there is a bug in Firefox at the moment, causing CSS selectors to not match elements in the <defs> section. The solution is to use the logo as the clippath, and move a blue rectangle in and out instead. svg#bogeLogo { display: block; left: 50%; position: absolute; top: 50%; transform: translate(-50%,-50%); } #bogePath { fill: transparent; stroke: red; stroke-width: 8; } svg#bogeLogo #bogeFinal { fill: blue; transition: all 1.4s ease-out !important; transform: translateX(-2552px); } svg#bogeLogo:hover #bogeFinal { transform: translateX(0px); } <svg id="bogeLogo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 2551.2 2551.2" style="enable-background:new 0 0 100 100;" xml:space="preserve"> <defs> <path id="bogePath" d="M1263.5,1239.5l0-1l0.8-1194.9l-60.3,0l-0.6,1195.9l-1146.6,0.2v60.3l1146.6-0.5v1195h59l1-1195 l1231.9,0.5l0-60.3L1263.5,1239.5z M779.6,1037c98.3-37.9,134.5-130.5,138.1-140c6.8-18.3,31.3-87,1.9-161.1 c-20.6-52-58.4-82.8-74.8-95.9c-23.2-18.5-45.4-27.8-61.3-34.5c13.2-6.5,52.6-26.9,76.7-90.2c26-68.5-0.8-128.3-7.7-143.8 c-25.5-57.3-74.1-84.5-95-96.9c-31.8-19-83.7-25.5-104.2-26.3L410.2,248v3.2l-1.1,800.3v1.1l293.7-0.2 C721.3,1051.7,748.9,1048.8,779.6,1037z M570.6,394.5c46.8-9.2,80.5-1.6,97.8,3.8c19.2,6.1,27.6,12.5,32.6,17.3 c22.3,21.1,22.8,51.6,23,61.4c0.2,9.5,0.7,37.9-19.2,61.4c-18.5,21.9-43.5,28.8-65.2,30.7c-31.6,2.7-51.9,2.2-69-1.9V394.5z M570.6,908.5V701.4c33.3-3.2,60.9-2.9,80.5-1.9c39.3,2,59.3,3.2,80.5,15.3c7,4,29.8,17.4,44.1,46c5.2,10.5,15.6,35.6,9.6,67.1 c-2.2,11.7-9.7,39.6-34.5,59.5c-11,8.7-25.4,16-63.3,21.1C660.3,912.2,620.2,914.9,570.6,908.5z M1835.5,1052.5 c218.7,0,395-184.3,395-403s-177.3-407-396-407s-396,188.3-396,407S1616.8,1052.5,1835.5,1052.5z M1835,390.5 c131.3,0,237.8,116.2,237.8,259.5S1966.3,909.5,1835,909.5S1597.2,793.3,1597.2,650S1703.7,390.5,1835,390.5z M636.5,1879.5v1l1,129 v0.1c73,0.1,142.9,0.3,216,0.4c-5.4,14.1-15,34.1-31.6,54.7c-5.9,7.2-35.7,43.1-89.4,63.7c-58.3,22.4-109.4,13.3-136.9,8.1 c-54.1-10.3-90.3-33.6-98.9-39.3c-39-25.9-60.5-55.8-71.8-71.8c-14.1-20-35.1-50.4-44.7-96.2c-2.4-11.6-10.4-54.2,2.7-107.1 c3.5-14.3,14.4-52.5,44.7-92.2c9.3-12.2,39.6-49.6,93.5-75.9c15.2-7.4,47.4-21.4,90.8-25.7c7.7-0.8,40-3.7,81.3,4.1 c19.2,3.6,46.7,9,77.2,25.7c14.7,8,31,19.8,63.7,43.4c8.8,6.3,15.7,12.5,20.5,16l90-106c-15.9-18.7-35.7-40.2-71-63 c-54-35-103.7-45.6-141.8-53.3c-31.3-6.3-86.6-17-158.1-6.3c-59.3,8.9-105.3,28.7-134.6,44.3c-49.5,26.2-82,56.1-95.8,69.6 c-39.5,38.6-60.6,75.2-65,83.1c-4.7,8.2-27.1,48.6-39.8,107.5c-2.3,10.9-9.1,44.7-9,89.4c0,22.3,0.4,59.9,13.6,106.6 c10.1,35.8,23.2,61,32.5,78.6c11,20.9,29,54.4,62.3,90.3c39,42.1,79.9,66.8,106.6,80.4c46.4,23.6,85.8,31.6,109.3,36.1 c25.3,4.9,72.3,11.8,131,6.3c27.9-2.6,61.2-6,102.1-21.7c14.8-5.7,58.3-23.6,103-63.2c42.8-37.9,65.1-76.5,79.5-102.1 c12.4-21.9,31.2-55.8,42.5-104.8c10.8-46.8,9.9-87,7.3-113.9L636.5,1879.5z M1019,1874.6c0,0.3,0.1,0.6,0.1,0.9l1.4,0L1019,1874.6z M1753.3,1919.6l291.8,1.1v-1.1l-1.1-142.2l-285.5,1.1h-1.1l1-137.9h1l304.6-3.3h1.1v-151.7h-464.6v2.1l-0.5,794l0,0.4h470.4v-146.4 h-317.1V1919.6z"/> <clipPath id="bogeClip"> <use xlink:href="#bogePath"/> </clipPath> </defs> <use xlink:href="#bogePath"/> <g clip-path="url(#bogeClip)"> <rect id="bogeFinal" x="0" y="0" height="100%" width="100%"/> </g> </svg>