I have a React App where I am displaying live updates on NFL games. I want to overlay a football field image with a dynamic rectangle SVG element that represents the distance covered by the team in yards, while the remaining distance is left uncovered. This is what I currently have implemented:
https://i.sstatic.net/fwLIM.png
Although I can adjust the size of the rectangle dynamically, it tends to shift position when the screen is resized, causing it to no longer align with the image.
Is there a way to ensure that the shading always covers a specific percentage of the image, regardless of the screen size? My current method is quite basic as I am still new to working with CSS:
<img className="col l5 offset-l2" src="./field.jpg" alt={this.props.team1} style={{height: "40%", width: "40%"}}></img>
<svg width="600" height="205" style={{ marginLeft: "635px", marginTop: "-110%", marginBottom: "1.5%" }}>
<rect width="206" height="210" style={{ zIndex: "9", position: "absolute", fill: "rgb(0,0,255)", opacity: "0.4", strokeWidth: "0", stroke: "rgb(0,0,0)" }} />
</svg>