Trouble with svg in firefox and IE - html

I have svg in my web site which works fine in chrome but when I try to check it on Firefox the thing is out of frame enlarged I think. I am a designer who started coding few months back. Here is the image for chrome and Firefox.
In Chrome:
In Firefox:
Here is the code snippet i used
svg {
display: block;
font: 10.5em 'Arial';
width: 960px;
height: 300px;
margin: 0 auto;
}
.text-copy {
fill: none;
stroke: white;
stroke-dasharray: 6% 29%;
stroke-width: 5px;
stroke-dashoffset: 0%;
animation: stroke-offset 5.5s infinite linear;
}
.text-copy:nth-child(1){
stroke: #4D163D;
animation-delay: -1s;
}
.text-copy:nth-child(2){
stroke: #840037;
animation-delay: -2s;
}
.text-copy:nth-child(3){
stroke: #BD0034;
animation-delay: -3s;
}
.text-copy:nth-child(4){
stroke: #BD0034;
animation-delay: -4s;
}
.text-copy:nth-child(5){
stroke: #FDB731;
animation-delay: -5s;
}
#keyframes stroke-offset{
100% {stroke-dashoffset: -35%;}
}
#media (min-width:768px){
svg{
width: 750px;
height: 300px;
margin: 0 auto;
}
}
#media (max-width:767px){
svg{
font: 6.5em 'Arial';
width: 100%;
height: 300px;
margin: 0 auto;
}
.text-copy {
fill: none;
stroke: white;
stroke-dasharray: 6% 29%;
stroke-width: 3px;
stroke-dashoffset: 0%;
animation: stroke-offset 5.5s infinite linear;
}
}
.text-center1{
color:rgba(255,255,255,0.8);
text-align: center;
font-size: 48px ;
margin-top:40px;
}
#media (max-width:992px){
.text-centre1{
font-size:30px;
}
}
<svg>
<symbol id="s-text">
<text text-anchor="middle" x="50%" y="80%">Digital</text>
</symbol>
<g class = "g-ants">
<use xlink:href="#s-text" class="text-copy"></use>
<use xlink:href="#s-text" class="text-copy"></use>
<use xlink:href="#s-text" class="text-copy"></use>
<use xlink:href="#s-text" class="text-copy"></use>
<use xlink:href="#s-text" class="text-copy"></use>
</g>
</svg>

This seems to be a bug in Firefox.
If you apply an em-based font size to the <svg> and have text inside a <symbol> then in Firefox, the <text> element thinks the font should be 10.5 times the current font size of 10.5em. In other words the font size is multiplying and ends up as 110.25em.
The simple solution is to move the font rule to the <text> ekement.
text {
font: 10.5em 'Arial';
}
svg {
display: block;
width: 960px;
height: 300px;
margin: 0 auto;
}
text {
font: 10.5em 'Arial';
}
.text-copy {
fill: none;
stroke: white;
stroke-dasharray: 6% 29%;
stroke-width: 5px;
stroke-dashoffset: 0%;
animation: stroke-offset 5.5s infinite linear;
}
.text-copy:nth-child(1){
stroke: #4D163D;
animation-delay: -1s;
}
.text-copy:nth-child(2){
stroke: #840037;
animation-delay: -2s;
}
.text-copy:nth-child(3){
stroke: #BD0034;
animation-delay: -3s;
}
.text-copy:nth-child(4){
stroke: #BD0034;
animation-delay: -4s;
}
.text-copy:nth-child(5){
stroke: #FDB731;
animation-delay: -5s;
}
#keyframes stroke-offset{
100% {stroke-dashoffset: -35%;}
}
#media (min-width:768px){
svg{
width: 750px;
height: 300px;
margin: 0 auto;
}
}
#media (max-width:767px){
svg{
width: 100%;
height: 300px;
margin: 0 auto;
}
text {
font: 6.5em 'Arial';
}
.text-copy {
fill: none;
stroke: white;
stroke-dasharray: 6% 29%;
stroke-width: 3px;
stroke-dashoffset: 0%;
animation: stroke-offset 5.5s infinite linear;
}
}
.text-center1{
color:rgba(255,255,255,0.8);
text-align: center;
font-size: 48px ;
margin-top:40px;
}
#media (max-width:992px){
.text-centre1{
font-size:30px;
}
}
<svg>
<symbol id="s-text">
<text text-anchor="middle" x="50%" y="80%">Digital</text>
</symbol>
<g class = "g-ants">
<use xlink:href="#s-text" class="text-copy"></use>
<use xlink:href="#s-text" class="text-copy"></use>
<use xlink:href="#s-text" class="text-copy"></use>
<use xlink:href="#s-text" class="text-copy"></use>
<use xlink:href="#s-text" class="text-copy"></use>
</g>
</svg>

As a rule of thumb, always include height,width and viewBox for svg images as attributes as opposed to CSS style. Different browsers render SVG differently if these attributes are not present.

Related

How to trigger an SVG Stroke-Dash animation on page load/Refresh

I'm trying to get a hover animation that is functioning correctly, to fire once when the page loads AND refreshes. It does appear to fire on INTIAL load but when I visit another section of the site and return, the animation does not fire again(hover continues to work). I know I need to use keyframes but i'm having trouble implementing it. The hover animation works perfectly, just not the keyframes for page load.
The SVG in HTML
<svg id="stroke" xmlns="http://www.w3.org/2000/svg" width="0" height="0">
<defs>
<path id="line" d="M2 2c49.7 2.6 50 3.1 100 1.7-46.5 2-93 4.4-139.2 7.3 45.2-1.5 90.6-1.8 135.8-.6" fill="none" stroke-linecap="round" stroke-linejoin="round" vector-effect="non-scaling-stroke"/>
</defs>
</svg>
<div class="home-body ">
<p class = 'entry-content'>My name is
<span class="first-name">
Hunter
<svg class="button-stroke" viewBox="0 0 154 5">
<use href="#line"></use>
</svg>
<svg class="button-stroke" viewBox="0 0 154 5">
<use href="#line"></use>
</svg>
</span><br></p>
CSS
.first-name {
display: inline-block;
color: white;
min-width: 154px;
text-decoration: none;
position: relative;
font-weight: bold;
}
.first-name:hover .button-stroke:nth-child(2) {
animation: strokeAnimation 1s ease-out;
stroke-dashoffset: 0;
}
.button-stroke:nth-child(2) {
animation: strokeAnimation 1s ease-out;
stroke-dasharray: 650px;
stroke-dashoffset: 650px;
stroke: #0d1117;
stroke-width: 5;
-webkit-transition: stroke-dashoffset 900ms ease-out;
transition: stroke-dashoffset 900ms ease-out;
}
.button-stroke {
display: block;
width: calc(100% - 40px);
height: 10px;
stroke: #ffcb47;
position: absolute;
stroke-width: 2;
}
#-webkit-keyframes strokeAnimation {
from {
stroke-dashoffset: 0;
stroke-dasharray: 650px;
stroke-dashoffset: 650px;
}
to {
stroke-dashoffset: 100%;
stroke-dasharray: 0px;
stroke-dashoffset: 0px;
}
}
#keyframes strokeAnimation {
from {
stroke-dashoffset: 0;
stroke-dasharray: 650px;
stroke-dashoffset: 650px;
}
to {
stroke-dashoffset: 100%;
stroke-dasharray: 0px;
stroke-dashoffset: 0px;
}
}
As you can see the animation does look like it is starting to trigger but backwards and then it flickers.

Why the middle stroke of the "W"'s letter is very sharp on my codepen?

Here the demo: https://codepen.io/joondoe/pen/XWrGgyo
here the code:
html, body {
height: 100%;
}
body {
background: #082330;
background-size: .12em 100%;
font: 16em/1 Arial;
}
h1 {
font-size: 0.15em;
margin: 30px;
font-family: Mansalva;
}
.text--line {
font-size: .5em;
}
svg {
position: absolute;
width: 100%;
height: 100%;
}
.text-copy {
fill: none;
stroke: white;
stroke-dasharray: 7% 28%;
stroke-width: 9px;
font-family: Mansalva;
-webkit-animation: stroke-offset 5s infinite linear;
animation: stroke-offset 5s infinite linear;
}
.text-copy:nth-child(1) {
stroke: #360745;
stroke-dashoffset: 7%;
}
.text-copy:nth-child(2) {
stroke: #D61C59;
stroke-dashoffset: 14%;
}
.text-copy:nth-child(3) {
stroke: #E7D84B;
stroke-dashoffset: 21%;
}
.text-copy:nth-child(4) {
stroke: #EFEAC5;
stroke-dashoffset: 28%;
}
.text-copy:nth-child(5) {
stroke: #1B8798;
stroke-dashoffset: 35%;
}
#-webkit-keyframes stroke-offset {
50% {
stroke-dashoffset: 35%;
stroke-dasharray: 0 87.5%;
}
}
#keyframes stroke-offset {
50% {
stroke-dashoffset: 35%;
stroke-dasharray: 0 87.5%;
}
}
<link href="https://fonts.googleapis.com/css?family=Dancing+Script|Mansalva&display=swap" rel="stylesheet">
<h1> Hey World </h1>
<svg viewBox="0 0 800 600">
<symbol id="s-text">
<text text-anchor="middle"
x="50%"
y="35%"
class="text--line"
>
Hey
</text>
<text text-anchor="middle"
x="50%"
y="68%"
class="text--line2"
>
World
</text>
</symbol>
<g class="g-ants">
<use xlink:href="#s-text"
class="text-copy"></use>
<use xlink:href="#s-text"
class="text-copy"></use>
<use xlink:href="#s-text"
class="text-copy"></use>
<use xlink:href="#s-text"
class="text-copy"></use>
<use xlink:href="#s-text"
class="text-copy"></use>
</g>
</svg>
I am wondering why the middle stroke of the "W"'s letter is very sharp in "Hey World" since it is very smooth in the original font -see the text.
thanks for any hint
It looks like pointy line join is not noticeable on the font because it is hidden by the font being filled in where your animated outline is not.
If you want to change it though see the stroke-linejoin attribute.

Adjusting Image automatically as per screen

An image is not adjusting as per the screen. See image google-play-badge.\
The width & height of the image is set to be auto, then also it is not resizing automatically.
My Codes:
body {
margin: 0;
padding: 0;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #000;
}
p {
position: relative;
font-family: sans-serif;
text-transform: uppercase;
font-size: 2em;
letter-spacing: 4px;
color: white;
display: flex;
justify-content: center;
overflow: hidden;
}
#supports (-webkit-text-fill-color: rgba(45, 45, 45, .05)) {
p {
background: linear-gradient(90deg, #000, #000fe6, #000);
background-repeat: no-repeat;
background-size: 80%;
animation: animate 3.75s linear infinite;
-webkit-background-clip: text;
-webkit-text-fill-color: rgba(45, 45, 45, .05);
}
}
#keyframes animate {
0% {
background-position: -500%;
}
100% {
background-position: 500%;
}
}
svg {
display: flex;
font: 10.5em 'Montserrat';
margin: 0 auto;
}
.text-copy {
fill: none;
stroke: white;
stroke-width: 5px;
stroke-dashoffset: 0%;
animation: stroke-offset 5.5s infinite linear;
}
#supports (stroke-dasharray: 6% 29%) {
.text-copy {
stroke-dasharray: 6% 29%;
}
}
.text-copy:nth-child(1) {
stroke: #4D163D;
animation-delay: -1;
}
.text-copy:nth-child(2) {
stroke: #840037;
animation-delay: -2s;
}
.text-copy:nth-child(3) {
stroke: #BD0034;
animation-delay: -3s;
}
.text-copy:nth-child(4) {
stroke: #BD0034;
animation-delay: -4s;
}
.text-copy:nth-child(5) {
stroke: #FDB731;
animation-delay: -5s;
}
#keyframes stroke-offset {
100% {
stroke-dashoffset: -35%;
}
}
#media screen and (max-width: 600px) {
p,
h3,
img {
font-size: 20px;
}
}
</style>
<body>
<div>
<h3>
<svg viewBox="0 0 960 300">
<symbol id="s-text">
<text text-anchor="middle" x="50%" y="80%">TITLE</text>
</symbol>
<g class = "g-ants">
<use xlink:href="#s-text" class="text-copy"></use>
<use xlink:href="#s-text" class="text-copy"></use>
<use xlink:href="#s-text" class="text-copy"></use>
<use xlink:href="#s-text" class="text-copy"></use>
<use xlink:href="#s-text" class="text-copy"></use>
</g>
</svg>
</h3>
<p>Some Text Here</p>
<div><img src="https://i.imgur.com/me74Rfr.png" alt="google-play-badge" width="auto" height="auto" /></div>
</div>
</body>
An image is not adjusting as per the screen. See image-alt google-play-badge.
The width & height of the image is set to be auto, then also it is not resizing automatically.
If you set width: 100% and max-width: 100% to your images, resizing will happen as expected.
body {
margin: 0;
padding: 0;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #000;
}
.fullWidthImage {
max-width: 100%;
width: 100%;
}
p {
position: relative;
font-family: sans-serif;
text-transform: uppercase;
font-size: 2em;
letter-spacing: 4px;
color: white;
display: flex;
justify-content: center;
overflow: hidden;
}
#supports (-webkit-text-fill-color: rgba(45, 45, 45, .05)) {
p {
background: linear-gradient(90deg, #000, #000fe6, #000);
background-repeat: no-repeat;
background-size: 80%;
animation: animate 3.75s linear infinite;
-webkit-background-clip: text;
-webkit-text-fill-color: rgba(45, 45, 45, .05);
}
}
#keyframes animate {
0% {
background-position: -500%;
}
100% {
background-position: 500%;
}
}
svg {
display: flex;
font: 10.5em 'Montserrat';
margin: 0 auto;
}
.text-copy {
fill: none;
stroke: white;
stroke-width: 5px;
stroke-dashoffset: 0%;
animation: stroke-offset 5.5s infinite linear;
}
#supports (stroke-dasharray: 6% 29%) {
.text-copy {
stroke-dasharray: 6% 29%;
}
}
.text-copy:nth-child(1) {
stroke: #4D163D;
animation-delay: -1;
}
.text-copy:nth-child(2) {
stroke: #840037;
animation-delay: -2s;
}
.text-copy:nth-child(3) {
stroke: #BD0034;
animation-delay: -3s;
}
.text-copy:nth-child(4) {
stroke: #BD0034;
animation-delay: -4s;
}
.text-copy:nth-child(5) {
stroke: #FDB731;
animation-delay: -5s;
}
#keyframes stroke-offset {
100% {
stroke-dashoffset: -35%;
}
}
#media screen and (max-width: 600px) {
p,
h3,
img {
font-size: 20px;
}
}
</style>
<body>
<div>
<h3>
<svg viewBox="0 0 960 300">
<symbol id="s-text">
<text text-anchor="middle" x="50%" y="80%">TITLE</text>
</symbol>
<g class = "g-ants">
<use xlink:href="#s-text" class="text-copy"></use>
<use xlink:href="#s-text" class="text-copy"></use>
<use xlink:href="#s-text" class="text-copy"></use>
<use xlink:href="#s-text" class="text-copy"></use>
<use xlink:href="#s-text" class="text-copy"></use>
</g>
</svg>
</h3>
<p>Some Text Here</p>
<div>
<img class="fullWidthImage" src="https://i.imgur.com/me74Rfr.png" alt="google-play-badge" width="auto" height="auto" />
</div>
</div>
</body>
<img src="https://i.imgur.com/me74Rfr.png" alt="google-play-badge" class="width100" />
In the above code class is added
add that class in style tag
.width100{
max-width:100%;
width:100%;
}

Image between SVG

#home {
height: 100vh;
background-image: url("http://4.bp.blogspot.com/-yB6Tc3mleuE/T4NkAKeazYI/AAAAAAAACB0/tlichKzIu3Q/s1600/Simple+unique+odd+weird+wallpapers+minimalistic+%2330+battleship+titanic.jpg");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
overflow: hidden;
padding: 0;
margin-left: -10px;
}
.background {
overflow: hidden;
}
#fg {
fill: pink;
stroke: #fff;
stroke-width: 10px;
stroke-dasharray: 1024px;
-webkit-animation: dash 2s;
animation: dash 2s;
}
#keyframes dash {
from {
stroke-dashoffset: 1024px;
}
to {
stroke-dashoffset: 0px;
}
}
#-webkit-keyframes dash {
from {
stroke-dashoffset: 1024px;
}
to {
stroke-dashoffset: 0px;
}
}
#bg {
fill: white;
stroke: none;
transform-origin: 1270px 550px;
-webkit-animation: bgfill 2s linear 2s forwards;
animation: bgfill 2s linear 2s forwards;
}
#keyframes bgfill {
from {
transform: scale(1);
}
to {
transform: scale(4);
}
}
#-webkit-keyframes bgfill {
from {
transform: scale(1);
}
to {
transform: scale(4);
}
}
<div id="home" class="section" style="height:100vh;">
<div class="background">
<svg viewBox="0 0 1376 764">
<defs>
<path id="shape" d="M1034.5,770.5a125.59,125.59,0,0,0-17-32c-12.32-16.72-25.68-25.84-33-31-6-4.23-59.88-42.55-100-90-13.64-16.14-20.57-24.48-26-38-15-37.48-3.73-73.65,0-85,8.68-26.45,23-43.26,35-57,19-21.82,33.56-29.9,67-54,33.68-24.27,55.39-39.91,77-60,40.56-37.69,35.94-49.35,81-96,34.18-35.39,51.27-53.08,79-65,7.79-3.35,76-31.44,140,2a142.06,142.06,0,0,1,31,22l7.5,7.5 L 1376,770.5 Z" />
</defs>
<use xlink:href="#shape" id="bg" />
<use xlink:href="#shape" id="fg" />
</svg>
</div>
</div>
I can not seem to make the background image visible at all times while remaining the same effect, making the fill transparent gets rid of the animation, I also tried to play around with z-index on various elements but without success, how can I make it so that the background image is visible inside the white line instead of the pink svg?
I also tried applying the same image to the pink SVG as fill and it kind of works, I just can not seem to make the image appear like how it would if it was full screen, it also makes the page a bit slow:
#fg {
fill: url(#image);
stroke: #fff;
stroke-width: 10px;
stroke-dasharray: 1024px;
-webkit-animation: dash 2s;
animation: dash 2s;
}
<pattern id="image" width="1" height="1">
<image xlink:href="http://4.bp.blogspot.com/-yB6Tc3mleuE/T4NkAKeazYI/AAAAAAAACB0/tlichKzIu3Q/s1600/Simple+unique+odd+weird+wallpapers+minimalistic+%2330+battleship+titanic.jpg"></image>
</pattern>
You can get rid of the pink with fill-opacity. But you would need to adjust the white "background" as it overlays the background-image.
You might need to change the shape for that.
You could also include the image as a layer in the svg.
#home {
height: 100vh;
background-image: url("http://4.bp.blogspot.com/-yB6Tc3mleuE/T4NkAKeazYI/AAAAAAAACB0/tlichKzIu3Q/s1600/Simple+unique+odd+weird+wallpapers+minimalistic+%2330+battleship+titanic.jpg");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
overflow: hidden;
padding: 0;
margin-left: -10px;
}
.background {
overflow: hidden;
}
#fg {
fill: pink;
fill-opacity: 0;
stroke: #fff;
stroke-width: 10px;
stroke-dasharray: 1024px;
-webkit-animation: dash 2s;
animation: dash 2s;
}
#keyframes dash {
from {
stroke-dashoffset: 1024px;
}
to {
stroke-dashoffset: 0px;
}
}
#-webkit-keyframes dash {
from {
stroke-dashoffset: 1024px;
}
to {
stroke-dashoffset: 0px;
}
}
#bg {
fill: white;
opacity: .5;
stroke: none;
transform-origin: 1270px 550px;
-webkit-animation: bgfill 2s linear 2s forwards;
animation: bgfill 2s linear 2s forwards;
}
#keyframes bgfill {
from {
transform: scale(1);
}
to {
transform: scale(4);
}
}
#-webkit-keyframes bgfill {
from {
transform: scale(1);
}
to {
transform: scale(4);
}
}
<div id="home" class="section" style="height:100vh;">
<div class="background">
<svg viewBox="0 0 1376 764">
<defs>
<path id="shape" d="M1034.5,770.5a125.59,125.59,0,0,0-17-32c-12.32-16.72-25.68-25.84-33-31-6-4.23-59.88-42.55-100-90-13.64-16.14-20.57-24.48-26-38-15-37.48-3.73-73.65,0-85,8.68-26.45,23-43.26,35-57,19-21.82,33.56-29.9,67-54,33.68-24.27,55.39-39.91,77-60,40.56-37.69,35.94-49.35,81-96,34.18-35.39,51.27-53.08,79-65,7.79-3.35,76-31.44,140,2a142.06,142.06,0,0,1,31,22l7.5,7.5 L 1376,770.5 Z" />
</defs>
<use xlink:href="#shape" id="bg" />
<use xlink:href="#shape" id="fg" />
</svg>
</div>
</div>

Loading animations not working in Edge

I have a loading animation that works perfectly fine in chrome and firefox but not at all in IE10 or edge.
This is my html:
<svg viewBox="0 0 120 120" version="1.1">
<symbol id="s-circle">
<circle r="10" cx="20" cy="20"></circle>
</symbol>
<g>
<#list 1..9 as i>
<g class="g-circle">
<use href="#s-circle"/>
</g>
</#list>
</g>
</svg>
and this is my scss:
$max: 9;
$angle: 360/$max;
$size: 160px;
$fill: $grey;
.cart__spinner {
position: relative;
overflow: hidden;
width: 280px;
height: 280px;
margin: 50px auto 0;
}
svg {
height: $size;
width: $size;
margin: 0 4em 4em;
overflow: visible;
}
#function transform($item: 1){
$base: rotate(#{-$angle*$item}deg) translate(5px, 5px);
#return $base;
}
.g-circle {
transform-origin: $size/2 $size/2;
fill: $fill;
animation: opacity 1.2s linear infinite;
#for $item from 1 through $max {
&:nth-child(#{$max}n + #{$item}) {
animation-delay: -#{$item/10}s;
transform: transform($item) scale(.9);
-ms-transform: transform($item) scale(.9);
}
}
}
#keyframes opacity {
0% {
fill-opacity: 1;
}
100% {
fill-opacity: 0;
}
}
#keyframes transform {
10% {
transform-origin: 70px 70px;
transform: scale(.75);
}
}
In IE10 or edge, there is just one dot on the page and not animation.
Can someone please explain why this is happening. Di I need to explicitly add support for IE?
Thanks
I figured my problem is that IE does not support animations on svg.