0

Hello, I'm having issues with styling multiple SVGs that cut through contents in a way so that they align properly even on window resize.

This is the result I want. desired effect It's one single SVG that wraps between two elements.

Here is my attempt at it using FlexBox

As shown above, I divided each path into their own SVG component (SvgIn, SvgMid, SvgOut)
so SvgIn and SvgOut may stretch vertically along with their adjacent element.

<div
  style={{
    width: "100%",
    height: "100%",
    backgroundColor: "#A0A0A0",
    margin: "50px"
  }}
>
  <section style={{ display: "flex", flexDirection: "row" }}>
    <SvgIn style={{ height: "100%", alignSelf: "flex-start" }} />
    <ContentOne
      style={{
        margin: "auto",
        width: "100px",
        height: "250px",
        backgroundColor: "red"
      }}
    />
  </section>

  <SvgMid style={{ alignSelf: "center", width: "100%", height: "auto" }} />

  <section style={{ display: "flex", flexDirection: "row" }}>
    <ContentTwo
      style={{
        margin: "auto",
        width: "300px",
        height: "150px",
        backgroundColor: "blue"
      }}
    />
    <SvgOut style={{ alignSelf: "flex-end", height: "auto" }} />
  </section>
</div>

The result isn't great

demonstration of align multiple svgs going wrong

  • The width of SvgIn and SvgOut aren't responsive unlike SvgMid where it's always 100% width of the parent, so it looks broken.
  • Despite 100% height, SvgIn and SvgOut does not stretch fully to fill the their own section container. (Turning preserveAspectRatio off does work but is there another way)
  • If possible, can this be achieved without extract each path in the svg but manipulate the paths directly.

The SVG components and full snippet is in this CodeSandbox

Thank you for helping out this confused beginner.

Terry
  • 149
  • 1
  • 3
  • 12
  • 2
    in case you are intrested here is a CSS solution: https://stackoverflow.com/q/56188930/8620333 .. simply need to do it from top to bottom – Temani Afif Jan 30 '20 at 20:30
  • @TemaniAfif The CSS solution with the one that retains transparency and gradient seems to work but the lines aren't as smooth. The curves will look very aliased/jagged since there are no line at all, but a mask over the background gradient. – Terry Jan 31 '20 at 00:07

0 Answers0