'Do I need to composite this image (frame), or am I over complicating the situation?

I have been tasked with a build that includes the following design. A gold frame with corner decorations.

enter image description here

Now, the divs this frame will be connected to will have a varied height and width. Using, for example, object-fit: contain would not work because the corner decorations will stretch and look misshapen.

The only real method I can think of is to break down each element and position them correctly. So as a quick example:


<div class="container">
    <div class="frame">
        <div class="corner corner__top--left"></div>
        <div class="line line__left"></div>
        <div class="corner corner__top--right"></div>
        <div class="line line__right"></div>
        <div class="corner corner__bottom--left"></div>
        <div class="line line__top"></div>
        <div class="corner corner__bottom--right"></div>
        <div class="line line__bottom"></div>
    </div>
</div>


.container {
  background: grey;
  width: 300px;
  height: 400px;
  position: relative;
}

.frame {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.corner {
    width: 50px;
    height: 50px;
    background-color: red;
    position: absolute;
}

.corner__top--left {
  top: 20px;
  left: 20px;
}

.corner__top--right {
  top: 20px;
  right: 20px;
}

.corner__bottom--left {
  bottom: 20px;
  left: 20px;
}

.corner__bottom--right {
  bottom: 20px;
  right: 20px;
}

.line {
  position: absolute;
  background: blue;
}

.line__left {
  left: 20px;
  top: 70px;
  height: calc(100% - 140px);
  width: 5px;
}

.line__right {
  right: 20px;
  top: 70px;
  height: calc(100% - 140px);
  width: 5px;
}

.line__top {
  left: 70px;
  top: 20px;
  width: calc(100% - 140px);
  height: 5px;
}

.line__bottom {
  left: 70px;
  bottom: 20px;
  width: calc(100% - 140px);
  height: 5px;
}

I'm wondering am I not seeing the wood for the trees and missing a glaringly obvious solution to this? Or is my only solution to composite the image in this way to retain the correct ratios?

Any input would be appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source