NextJS Tailwind - Plain CSS Animation not working - css

I'm trying to get an animation working that I found here: https://codepen.io/goodkatz/pen/LYPGxQz.
I moved some of the animation code to tailwind for the React Component and left some code as plain css. When I run the component in Storybook it works like a charm, but when I run it with next dev, the animation doesn't work, it doesn't move whatsoever.
Here is the component:
import React from "react";
import "../../styles/WavesBackground.module.css";
export interface WavesBackgroundProps extends React.PropsWithChildren {}
export const WavesBackground: React.FC<WavesBackgroundProps> = () => {
return (
<div className="relative text-center bg-gradient-to-t from-lightgreen to-darkgreen m-0 p-0 w-full h-4/6">
<div>
<div className="m-0 p-0 w-full h-4/6 flex justify-center items-center text-center">
<h1 className="font-light tracking-wide text-5xl h-24"></h1>
</div>
<svg
className="waves relative w-full h-1/3 max-h-96 min-h-150px"
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
viewBox="0 24 150 28"
preserveAspectRatio="none"
shapeRendering="auto"
>
<defs>
<path
id="gentle-wave"
d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z"
/>
</defs>
<g className="parallax">
<use
xlinkHref="#gentle-wave"
x="48"
y="0"
fill="rgba(255,255,255,0.7"
/>
<use
xlinkHref="#gentle-wave"
x="48"
y="3"
fill="rgba(255,255,255,0.5)"
/>
<use
xlinkHref="#gentle-wave"
x="48"
y="5"
fill="rgba(255,255,255,0.3)"
/>
<use xlinkHref="#gentle-wave" x="48" y="7" fill="#fff" />
</g>
</svg>
</div>
</div>
);
};
And here is the plain CSS file:
.waves {
position: relative;
width: 100%;
height: 20vh;
margin-bottom: -7px; /*Fix for safari gap*/
min-height: 100px;
max-height: 150px;
}
/* Animation */
.parallax > use {
animation: move-forever 25s cubic-bezier(0.55, 0.5, 0.45, 0.5) infinite;
}
.parallax > use:nth-child(1) {
animation-delay: -2s;
animation-duration: 7s;
}
.parallax > use:nth-child(2) {
animation-delay: -3s;
animation-duration: 10s;
}
.parallax > use:nth-child(3) {
animation-delay: -4s;
animation-duration: 13s;
}
.parallax > use:nth-child(4) {
animation-delay: -5s;
animation-duration: 20s;
}
#keyframes move-forever {
0% {
transform: translate3d(-90px, 0, 0);
}
100% {
transform: translate3d(85px, 0, 0);
}
}
/*Shrinking for mobile*/
#media (max-width: 768px) {
.waves {
height: 40px;
min-height: 40px;
}
.content {
height: 30vh;
}
}

I don't know if it's the best way to fix it, but it got fixed by moving the css out of a module.css file and into the globa.css file.

Related

Calculate Angle for Rotation in Pure CSS

I would like to use CSS animations to move an SVG along a linear path across a full-window page with aligning the SVG to this path. Referring to the figure below with the path shown as a red line, I want to specify h in multiples of vh and w in multiples of vw, e.g. h = 30vh, w = 60vw, and calculate the angle α for rotating the SVG shown as the blue triangle.
Or course, this should be responsive and work with different window sizes. I was hoping to do all this in pure CSS.
Following tan(α) = w/h, I can use the arcus tangens function to calculate the angle α from the quotient w/h. Since trigonometric function are not available in CSS yet, I could use a series approximation for calculating the angle as demonstrated here. But the actual show-stopper seems to be the calculation of the quotient w/h as divisions in CSS require the denominator to be unitless. So, 60vw / 30vh is not allowed.
Is there a different way to calculate or set the angle in CSS? Or do I have to fall back to a JavaScript solution here?
Edit: Here is a minimal reproducible example. In order to set the rotation in the first keyframe, the actual angle α would be required. It is currently fixed to rotate(0deg) so the triangle always points upwards instead in the direction of the linear path.
body {
overflow: hidden;
}
main {
color: black;
background-color: #8dbdff;
}
svg#example {
position: absolute;
top: 0%;
left: 0%;
transform: translate(-100%, -100%);
width: 30px;
height: 30px;
animation: linear-motion 3.0s linear infinite;
}
#keyframes linear-motion {
0% {
transform: translate(0, 30vh) translateX(-100%) rotate(0deg);
}
100% {
transform: translate(60vw, 0vh) translateY(-100%);
}
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<main class="container-fluid d-flex align-items-center min-vh-100">
<svg id="example" xmlns="http://www.w3.org/2000/svg" version="1.1" width="100" height="100" viewBox="0 0 100 100">
<path fill="#008aff" d="M 50,5 95,97.5 5,97.5 z"/>
</svg>
</main>
Following A Haworth's comment, I finally used vmin to create animations with fixed ratios. This ratio can then be used to pre-calculate an angle as shown in the snippet below.
This solution has some limitations but is responsive and works with different window sizes.
body {
overflow: hidden;
}
main {
color: black;
background-color: #8dbdff;
}
svg#example {
position: absolute;
top: 0%;
left: 0%;
transform: translate(-100%, -100%);
width: 30px;
height: 30px;
animation: linear-motion 3.0s linear infinite;
}
#keyframes linear-motion {
0% {
transform: translate(-100%, 40vmin) rotate(66.03deg);
}
100% {
transform: translate(90vmin, -100%) rotate(66.03deg);
}
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<main class="container-fluid d-flex align-items-center min-vh-100">
<svg id="example" xmlns="http://www.w3.org/2000/svg" version="1.1" width="100" height="100" viewBox="0 0 100 100">
<path fill="#008aff" d="M 50,5 95,97.5 5,97.5 z"/>
</svg>
</main>

React-Native Parent View opacity inherit in child View

I am trying to build Screen like below but in the result parent view opacity inherit inside child view too.is anyone knows how to resolve this issue
below are the what am i trying to create and the result what i get.
what i want:
result what i get:
Code
<View style={styles.container} >
<Image
source={{
uri: 'http://i.imgur.com/sIaHZ9i.png',
}}
style={styles.image} >
</Image>
<View style={styles.subcontainer} >
<View style={styles.locationview}>
<View
style={styles.lastcircle}>
<View
style={styles.last} /></View>
<Entypo
name="location-pin"
style={styles.icon}
size={35}
/>
</View>
<View style={styles.contentContainer} >
<Text style={styles.title}>DELIVERING TO</Text>
<Text style={styles.text}>Locating...</Text>
</View>
</View>
</View>
CSS
subcontainer:{
flex:1,
backgroundColor:'rgba(255, 255, 255,0.8)',
alignItems:'center',
justifyContent:'center'
},
locationview:{
height:130,
width:130,
borderColor:'#CAD5E2',
borderWidth:1,
borderRadius:70,
marginBottom:20,
},
If you post to and join the Geographic Information Systems Stack Exchange they might have some helpful tips in CSS and supply more people understanding your map related problem https://gis.stackexchange.com/
Here are a few other resources that might help:
https://gis.stackexchange.com/questions/106811/make-leaflet-map-background-transparent
change opacity of image.map area
https://www.sitepoint.com/community/t/change-opacity-of-an-area-of-an-image/274316
Check out Codepen.io too which had a solution by Paul O'Brien on spot opacity in CSS , but StackOverflow won't allow me to link it here.
This is not my code, This is the code from Paul O Brien on Codepen
CSS :
.hole {
position: relative;
display: inline-table;
margin:10px;
}
.hole img {
opacity: 0.5;
}
.hole:after{
content: "";
position: absolute;
z-index: 2;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
background: url(https://picsum.photos/300/300) no-repeat 0 0;
border-radius: 50%;
}
.hole2 img,.hole3 img{
filter: blur(2px);
}
.hole3:after{
width:100px;
height:100px;
margin:auto;
background-size:300px 300px;
background-position:50% 50%;
}
.hole4:after{
transition:all 2s ease;
margin:0;
background-position:0% 0%;
}
.hole4:hover:after{
background-position:100% 100%;
margin:calc(100% - 100px) 0 0 calc(100% - 100px);
}
.hole5:after{
transition:all 1s ease;
height:0;
width:0;
}
.hole5:hover:after{
width:150px;
height:150px;
}
<div class="hole hole1">
<img src="https://picsum.photos/300/300" width="300" height="300" alt="Sea View">
</div>
<div class="hole hole2">
<img src="https://picsum.photos/300/300" width="300" height="300" alt="Sea View">
</div>
<div class="hole hole3">
<img src="https://picsum.photos/300/300" width="300" height="300" alt="Sea View">
</div>
<div class="hole hole3 hole4">
<img src="https://picsum.photos/300/300" width="300" height="300" alt="Sea View">
</div>
<div class="hole hole3 hole5">
<img src="https://picsum.photos/300/300" width="300" height="300" alt="Sea View">
</div>
<p>(Hover the last 2 images)</p>

How can I make an inline-SVG fit it's container after a transform?

I'm trying to rotate a graph made in SVG when the viewport is smaller than 600px. I used a media querie and it work great but the svg is overflowing from it's container and whatever I do, I can't fix it.
Is it possible to fix it without javascript ?
I tried to use the preserveAspectRatio attribute and the viewbox attribute but it doesnt work.
Here's the code : https://codepen.io/telumire-the-sasster/pen/vYBxLRg
HTML :
<div class="container">
<svg viewBox="0 0 700 100" preserveAspectRatio="none" class="graphic" style="">
<polyline fill="red" stroke="none"
points="
0,0
0,15
100,14
200,18
300,21
400,23
500,22
600,17
700,17
700,0
0,0
"/>
</svg>
</div>
CSS :
.container {
background-color: green;
}
.graphic {
transform: scaleY(-1);
}
#media (max-width: 599px) {
/* smartphone */
.graphic {
transform: rotate(90deg);
height: 100%;
display: block;
}
}
I expect the svg to not overflow from the green container (it must fit it's height).
The height of your svg doesnt not exceed the height of your container. Problem is you turn your svg 90 degrees so that visually it's width becomes it's height, but that's only visually, cos it's still counted as width.
EDIT:
Added a jQuery solution. With this setup if viewport is smaller than 600 your svg will be rotated as before but JavaScript will replace height value with width value and width value with height value. Here is the code:
$(window).resize(function() {
if ($(window).width() <= 600) {
var h = $('#svg').height();
var w = $('#svg').width();
$('#svg').attr('width', h);
$('#svg').attr('height', w);
}
});
.container {
background-color: green;
}
.graphic {
transform: scaleY(-1);
}
#media (max-width: 599px) {
/* smartphone */
.container {
height: 200px;
}
.graphic {
transform: rotate(90deg);
height: 100%;
display: block;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
<svg viewBox="0 0 700 100" preserveAspectRatio="none" class="graphic" style="" id="svg">
<polyline fill="red" stroke="none" points="
0,0
0,15
100,14
200,18
300,21
400,23
500,22
600,17
700,17
700,0
0,0
" />
</svg>
</div>
Other choice would be placing 2 svgs (one vertically and one horizontally aligned) and displaying only one of them at a time.
For anyone interested, I've finally settled with using 2 inline svg :
HTML :
<div class="container">
<svg
viewBox="0 0 700 100"
preserveAspectRatio="none"
class="graphic landscape"
>
<!-- <g transform="translate(0,100)"></g><g transform="scale(1,-1)"></g> -->
<polyline
fill="lightgrey"
stroke="none"
points="
0,0
0,60
100,56
200,72
300,84
400,92
500,88
600,68
700,68
700,0
"
/>
</svg>
<svg
viewBox="0 0 100 700"
preserveAspectRatio="none"
class="graphic portrait"
>
<!-- <g transform=" translate(0,100) "></g><g transform="scale(1,-1) "></g> -->
<polyline
fill="lightgrey "
stroke="none "
points="
0,0
60,0
56,100
72,200
84,300
92,400
88,500
68,600
68,700
0,700
"
/>
</svg>
</div>
CSS :
.container {
background-color: green;
height: 50vh;
}
.graphic {
transform: scaleY(-1);
overflow-x: hidden;
overflow-y: hidden;
}
.landscape {
display: block;
width: 100%;
/* max-height: 100%; */
height: 100%;
}
.portrait {
display: none;
height: 100%;
/* max-width: 100%; */
width: 100%;
}
#media (max-width: 599px) {
/* smartphone */
.portrait {
display: block;
}
.landscape {
display: none;
}
}
Next step is using js to automate the coordinate of the second graph I guess
EDIT: You should actually use display: none; and display: block; here, since visibility: hidden; and visibility: visible; doesnt show the tag too but allocate space for it and we want to avoid that.

Why Doesn't This CSS Transition Work On SVG Inside an Anchor

I'm trying to transition the fill and path of an embedded SVG object, however this doesn't seem to work (Code Pen here):
The SVG:
<a class="simple-link svg-link" href="">
Some Text
<svg version="1.1" id="next-page-icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 25 25" enable-background="new 0 0 25 25" xml:space="preserve" preserveAspectRatio="xMinYMin meet">
<circle class="the-background" cx="12.5" cy="12.5" r="12.5"/>
<g>
<path class="the-icon" d="M16.088,11.421l-3.404,3.362l-3.418-3.362v-1.204l3.418,3.444l3.404-3.444V11.421z"/>
</g>
</svg>
</a>
The Sass:
a
{
width:200px;
height:200px;
overflow: hidden;
#include transition(color, 1s);
#include transition(background, 1s);
svg
{
width:200px;
height:200px;
.the-background
{
#include transition(fill, 1s);
fill: grey;
}
.the-icon
{
#include transition(fill, 2.5s);
}
}
&:hover
{
color: red;
background: black;
.the-background
{
fill: black;
}
.the-icon
{
fill: red;
}
}
}
Why don't the fills animate on hover?
The way I solved this problem was to place fill="currentColor" on the svg path element that I wanted to transition. Then I added color and transition properties to the surrounding anchor tag and performed the CSS transition on the anchor tag instead of the svg path itself. Below is a very stripped down example:
HTML:
<a>
<svg>
<path fill="currentColor" />
</svg>
</a>
SCSS:
a { color: black; transition: color .2s linear;
&:hover { color: white; } }
The reason why the transition doesn't work is because it is within a link.
To fix it, put the link inside of the SVG instead like this SO post suggests
OR
Make the SVG a sibling of the link and use the sibling selector
/* This goes within `a { ...` */
&:hover + svg { /* Or use ~ to select all */
.the-background
{
fill: black;
}
.the-icon
{
fill: red;
}
}
I just discovered that in order to transition an svg fill within an anchor element, it only works using rgba color codes. I haven't researched why that is, but it's working on my projects - here's an example: http://rawesome.leveragenewagemedia.com/ (hover the social media icons).
Here's the SASS I'm using:
.icon {
display: inline-block;
width: 20px;
height: 20px;
fill: rgba(0,0,0,.2);
-webkit-transition: fill .5s;
-moz-transition: fill .5s;
-ms-transition: fill .5s;
-o-transition: fill .5s;
transition: fill .5s;
&:hover {
fill: rgba(0,0,0,.5);
}
}
I have to contradict the marked answer because, at least at this point in time, the statement, svg transitioning and animating wouldn't work inside an anchor tag is simply not true.
Working example:
<!doctype html>
<html>
<body>
<a>
<svg width="100%" height="100%" viewBox="0 0 800 600" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;">
<path d="M211.281,336.939C211.281,336.939 285.671,363.039 355.793,360.727C425.915,358.414 439.329,333.635 491.159,336.939C491.159,336.939 494.646,428.533 356.402,433.741C219.839,438.885 216.224,360.378 211.281,336.939Z" style="stroke:#000;stroke-width:46.14px;"/>
<path d="M244.207,187.195C259.451,224.852 289.939,244.499 311.28,197.019" style="fill:none;stroke:#000;stroke-width:46.14px;"/>
<path d="M383.841,219.954C406.402,233.327 447.866,257.844 461.89,198.78" style="fill:none;stroke:#000;stroke-width:46.14px;"/>
</svg>
</a>
</body>
<style>
svg>path{
transition: 1s;
}
svg path:nth-of-type(1){
fill:#ffe7cb;
}
svg:hover>path:nth-of-type(1){
d: path("M211.89,300C211.89,300 286.281,348.171 356.402,343.902C426.524,339.634 439.939,293.902 491.768,300C491.768,300 495.256,469.047 357.012,478.659C220.449,488.153 216.834,343.258 211.89,300Z");
fill:white;
}
svg:hover>path:nth-of-type(2){
d: path("M244.207,187.195C259.451,173.171 289.939,165.854 311.28,183.537");
}
svg:hover>path:nth-of-type(3){
d: path("M383.841,187.195C406.402,179.878 447.866,166.463 461.89,198.78");
}
a{
height: 300px;
width: 400px;
display: block;
}
</style>
</html>

Vertically center SVG Tag

I'm trying to figure out a way to center vertically my SVG Tag.
Basically, here is a simplified SVG code i'm trying to center :
<svg height="272" style="background-color:transparent;margin-left: auto; margin-right: auto;" width="130" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g style="font-size: 0.7em;" transform="scale(1 1) rotate(0) translate(0 270)">
<g id="1" style="font-size: 0.7em;">
<image height="32" width="32" x="49" xlink:href="../../images/JOB.GIF" y="-270"/>
</g>
</g>
</svg>
I have no trouble putting it in the middle (horizontally speaking) of the page, however i'd like it to be vertically centered as well.
I can add wrappers, but i'd like to know a generic way of doing this, not depending on the SVG size nor the window size.
I have tried multiple ways, but nothing worked.
Thanks,
I updated this answer as current browser have a lot better solution for that.
How wise man said, first year you learn html and css, for another few years you learn advanced javascript and after five years you finally learn how to vertically center div.
to vertically/horizontally align anything in css you can use two main ways:
Absolute
<div class="outside">
<div class="inside">Whatever</div>
</div>
and css:
.outside{
position:relative;
}
.inside{
position:absolute;
top:50%;
bottom:50%;
transform:translate(-50%, -50%);
}
the only issue with that is that element doesn't generate the height.
Flexbox
Flexbox has now pretty good support so why not to use it. https://caniuse.com/#feat=flexbox
Using flexbox your item doesn't need to be absolute so it will generate the height. code:
<div class="outside">
<div>Whatever</div>
</div>
and css:
.outside{
display: flex;
align-items: center;
justify-content: center;
}
Old answer:
you have height and width so u can use margin : auto auto;
or put it in div with
position:absolute ;
left:50% ;
margin-left: -(half of width of image)px;
top:50% ;
margin-top: -(half of height of image)px;
the second one will be better if u will be doing some stuff with it (javascript animation or something)
I didn't check it but maybe u can use second option for svg (without outer div) too
It's Simple!
HTML:
<div class="a">
<div class="b">
<div class="c">
<!-- Your SVG Here -->
</div>
</div>
</div>
CSS:
<style>
.a {
display: table;
position: absolute;
height: 100%;
width: 100%;
}
.b {
display: table-cell;
vertical-align: middle;
}
.c {
margin-left: auto;
margin-right: auto;
height: /* Your size in px, else it will expand to your screen size!*/
width: /* Your size in px, else it will expand to your screen size!*/
}
</style>
If you provide your svg element with a viewBox attribute and set it's width & height attributes to 100% then all should be well (in most browsers..)
$(document).ready(function(){
$(".panel-left").resizable({handleSelector: ".splitter",containment: "parent"});
});
#ctr
{
position: absolute;
border: 1px solid #131313;
top: 5%;
left: 5%;
bottom: 5%;
right: 5%;
display: flex;
flex-direction: row;
}
#ctr svg
{
height: 100%;
width: 100%;
}
.panel-left
{
flex: 0 0 auto;
padding: 10px;
width: 50px;
min-height: 50px;
min-width: 50px;
max-width: 80%;
max-height: 100%;
white-space: nowrap;
background: #131313;
color: white;
}
.splitter
{
flex: 0 0 auto;
width: 18px;
}
.panel-right
{
flex: 1 1 auto;
padding: 10px;
min-width: 20px;
background: #eee;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div style="visibility:hidden; position:absolute; width:0">
<svg>
<g id="my-funky-svg-defs">
<defs>
<radialGradient id="gradient" cx="25%" cy="25%" r="100%" fx="40%" fy="40%">
<stop offset= "0%" stop-color="hsla(313, 80%, 80%, 1)"/>
<stop offset= "40%" stop-color="hsla(313, 100%, 65%, 1)"/>
<stop offset="110%" stop-color="hsla(313, 100%, 50%, 0.7)"/>
</radialGradient>
</defs>
<title>smarteee</title>
<circle class="face" cx="200" cy="200" r="195" fill="url(#gradient)" />
<ellipse class="eye eye-left" cx="140" cy="150" rx="10" ry="40" fill="#131313"/>
<ellipse class="eye eye-right" cx="260" cy="150" rx="10" ry="40" fill="#131313"/>
<path class="smile" d="M120,280 Q200,330 280,280" stroke-width="10" stroke="#131313" fill="none" stroke-linecap="round"/>
</g>
</svg>
</div>
<div id=ctr>
<div class="panel-left">
<svg viewBox="0 0 400 400"><use xlink:href="#my-funky-svg-defs"></use></svg>
</div>
<div class="splitter">
</div>
<div class="panel-right">
<svg viewBox="0 0 400 400"><use xlink:href="#my-funky-svg-defs"></use></svg>
</div>
</div>
&here's a corresponding jsfiddle to play with
NB: there is also the preserveAspectRatio attribute that works in conjunction with the viewBox settings. eg: preserveAspectRatio="xMidYMid meet"
You could try using flexbox.
Simple HTML:
<div class="outside">
<svg />
</div>
CSS:
.outside {
display: flex;
align-items: center; /* vertical alignment */
justify-content: center; /* horizontal alignment */
}
HTML with your sample:
<div class="outside">
<svg height="272" style="background-color:transparent;margin-left: auto; margin-right: auto;" width="130" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g style="font-size: 0.7em;" transform="scale(1 1) rotate(0) translate(0 270)">
<g id="1" style="font-size: 0.7em;">
<image height="32" width="32" x="49" xlink:href="../../images/JOB.GIF" y="-270"/>
</g>
</g>
</svg>
</div>
Flexbox browser support: caniuse flexbox
Learn about Flexbox: CSS Tricks Guide to Flexbox
Learn by playing: Flexbox Froggy
I've finally used some JS code to do so.
I was using the solution from here : Best way to center a <div> on a page vertically and horizontally?
Which is :
div {
width: 100px;
height: 100px;
background-color: red;
position: absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
But the problem is that if the SVG is bigger than the window size, it gets cropped.
Here is the JS code i've used in onLoad :
var heightDiff = window.innerHeight - svg.height.baseVal.value;
var widthDiff = window.innerWidth - svg.width.baseVal.value;
if (heightDiff > 0)
svg.style.marginTop = svg.style.marginBottom = heightDiff / 2;
if (widthDiff > 0)
svg.style.marginLeft = svg.style.marginRight = widthDiff / 2;

Resources