title: HTML/CSS_IMG and SVG layering
body: <p>I need to solve issue with layering. On the background I need to have <code>rect</code>, then above it <code>img</code> and all other elements on the top, like in the example picture. I tried to use <code>z-index</code> for this.</p>
  <p><a href="https://i.stack.imgur.com/yEuZv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yEuZv.png" alt="enter image description here" /></a></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;title&gt;z-index&lt;/title&gt;
  
      &lt;style&gt;
        svg {
          width: 500px;
          height: 300px;
        }
  
        .img-overlay-wrap img {
          position: absolute;
          top: 20px;
          left: 80px;
          z-index: 0;
        }
  
        .img-overlay-wrap svg {
          position: absolute;
          top: 0px;
          left: 0px;
          z-index: -1;
        }
  
        .front {
          position: absolute;
          z-index: 1;
        }
      &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div class="img-overlay-wrap"&gt;
        &lt;h1&gt;Header&lt;/h1&gt;
        &lt;svg&gt;
          &lt;rect x="0" y="0" width="500" height="300" fill="#dcd1c4"&gt;&lt;/rect&gt;
          &lt;g class="front"&gt;
            &lt;text style="color: #538b01;" x="150" y="150"&gt;SVG Text&lt;/text&gt;
            &lt;line x1="34" y1="47" x2="279" y2="47" stroke="black" /&gt;
          &lt;/g&gt;
        &lt;/svg&gt;
        &lt;img
          src="https://4.bp.blogspot.com/-6QFHkPCFUJE/US10_Byu7TI/AAAAAAAADm0/zRcsPaMQpp8/s1600/pink+camellia.jpg"
          height="200"
        /&gt;
      &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>Approach to put <code>img</code> in between 2 SVG-elements gave same result:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;title&gt;z-index&lt;/title&gt;
  
      &lt;style&gt;
        svg {
          width: 500px;
          height: 300px;
        }
  
        .img-overlay-wrap img {
          position: absolute;
          top: 20px;
          left: 80px;
          z-index: 0;
        }
  
        .img-overlay-wrap svg {
          position: absolute;
          top: 0px;
          left: 0px;
          z-index: -1;
        }
  
        .front {
          position: absolute;
          z-index: 1;
        }
      &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div class="img-overlay-wrap"&gt;
        &lt;h1&gt;Header&lt;/h1&gt;
        &lt;svg&gt;
          &lt;rect x="0" y="0" width="500" height="300" fill="#dcd1c4"&gt;&lt;/rect&gt;
        &lt;/svg&gt;
        &lt;img  src="https://4.bp.blogspot.com/-6QFHkPCFUJE/US10_Byu7TI/AAAAAAAADm0/zRcsPaMQpp8/s1600/pink+camellia.jpg"
          height="200"
        /&gt;
        &lt;svg&gt;
          &lt;text style="color: #538b01;" x="150" y="150"&gt;SVG Text&lt;/text&gt;
          &lt;line x1="34" y1="47" x2="279" y2="47" stroke="black" /&gt;
        &lt;/svg&gt;
      &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>Tried tag <code>use</code> with the attribute <code>xlink:href</code>, but also without success:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;title&gt;z-index&lt;/title&gt;
  
      &lt;style&gt;
        svg {
          width: 500px;
          height: 300px;
        }
  
        .img-overlay-wrap img {
          position: absolute;
          top: 20px;
          left: 80px;
          z-index: 0;
        }
  
        .img-overlay-wrap svg {
          position: absolute;
          top: 0px;
          left: 0px;
          z-index: -1;
        }
  
        .front {
          position: absolute;
          z-index: 1;
        }
      &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div class="img-overlay-wrap"&gt;
        &lt;h1&gt;Header&lt;/h1&gt;
        &lt;svg&gt;
          &lt;rect x="0" y="0" width="500" height="300" fill="#dcd1c4"&gt;&lt;/rect&gt;
          &lt;g class="front"&gt;
            &lt;text style="color: #538b01;" x="150" y="150"&gt;SVG Text&lt;/text&gt;
            &lt;line x1="34" y1="47" x2="279" y2="47" stroke="black" /&gt;
          &lt;/g&gt;
          &lt;use xlink:href=".front"/&gt;
        &lt;/svg&gt;
        &lt;img
          src="https://4.bp.blogspot.com/-6QFHkPCFUJE/US10_Byu7TI/AAAAAAAADm0/zRcsPaMQpp8/s1600/pink+camellia.jpg"
          height="200"
        /&gt;
      &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>