Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flip an svg along the x-axis so it's upside down

Tags:

css

svg

I am trying to flip this SVG that I found on here so that the whitespace is on the bottom and the wave is on the top, but I can't figure out how to go about it. Any suggestions?

body {
  margin: 0;
}
footer {
  position: absolute;
  width: 100%;
  height: 100px;
  bottom: 0;
  overflow: hidden;
}
<footer>
  <svg viewBox="0 -20 700 110" width="100%" height="110" preserveAspectRatio="none">
    <path transform="translate(0, -20)" d="M0,10 c80,-22 240,0 350,18 c90,17 260,7.5 350,-20 v50 h-700" fill="#CEB964" />
    <path d="M0,10 c80,-18 230,-12 350,7 c80,13 260,17 350,-5 v100 h-700z" fill="#00273F" />
  </svg>
</footer>
like image 729
dotwongdotcom Avatar asked Feb 03 '18 21:02

dotwongdotcom


2 Answers

The simplest would possibly be to use a CSS transform to rotate by 180 degrees. Since the initial value for transform-origin is 50% 50% 0 the rotation happens around the center. This avoids the need to actually modify the SVG.

body {
  margin: 0;
}
footer {
  position: absolute;
  width: 100%;
  height: 100px;
  bottom: 0;
  overflow: hidden;
  transform: rotate(180deg);
}
<footer>
  <svg viewBox="0 -20 700 110" width="100%" height="110" preserveAspectRatio="none">
    <path transform="translate(0, -20)" d="M0,10 c80,-22 240,0 350,18 c90,17 260,7.5 350,-20 v50 h-700" fill="#CEB964" />
    <path d="M0,10 c80,-18 230,-12 350,7 c80,13 260,17 350,-5 v100 h-700z" fill="#00273F" />
  </svg>
</footer>

Note that this doesn't actually "flip", but rotate. If flipping is more appropriate, scaleY with a value of -1 can be used as well. It scales along the transform-origin as well, so the above holds here as well.

body {
  margin: 0;
}
footer {
  position: absolute;
  width: 100%;
  height: 100px;
  bottom: 0;
  overflow: hidden;
  transform: scaleY(-1);
}
<footer>
  <svg viewBox="0 -20 700 110" width="100%" height="110" preserveAspectRatio="none">
    <path transform="translate(0, -20)" d="M0,10 c80,-22 240,0 350,18 c90,17 260,7.5 350,-20 v50 h-700" fill="#CEB964" />
    <path d="M0,10 c80,-18 230,-12 350,7 c80,13 260,17 350,-5 v100 h-700z" fill="#00273F" />
  </svg>
</footer>
like image 81
mmlr Avatar answered Sep 19 '22 17:09

mmlr


You may use scale transformation and adjust the viewbox like this:

body {
  margin: 0;
}
footer {
  position: absolute;
  width: 100%;
  height: 100px;
  bottom: 0;
  overflow: hidden;
}
<footer>
  <svg viewBox="0 -70 700 110" width="100%" height="110" preserveAspectRatio="none">
   <g transform="scale(1,-1)">
   <path transform="translate(0, -20)" d="M0,10 c80,-22 240,0 350,18 c90,17 260,7.5 350,-20 v50 h-700" fill="#CEB964" />
    <path d="M0,10 c80,-18 230,-12 350,7 c80,13 260,17 350,-5 v100 h-700z" fill="#00273F" />
    </g>
  </svg>
</footer>
like image 29
Temani Afif Avatar answered Sep 20 '22 17:09

Temani Afif