I'm currently working on adding an overlay to my image in order to darken it and display text over the top. I've tried using absolute positioning for both the image and overlay, but the overlay ends up covering the entire window and sitting above the text. What I want is for it to look like this:
https://i.stack.imgur.com/YsBAc.png
Check out the CodeSandbox here: https://codesandbox.io/s/amazing-mendeleev-gohz7?file=/src/App.tsx
Here's the code snippet:
<div className="container" style={{ padding: "30px" }}>
<img style={{ borderRadius: "10px" }} src="dubai.png"></img>
<div
style={{
background: "rgba(0, 0, 0, 0.5)",
width: "100%",
height: "100%",
zIndex: 1,
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)"
}}
></div>
<div
style={{
color: "#fff",
position: "absolute",
top: "20%",
left: "50%",
transform: "translate(-50%, -100%)",
fontFamily: "Roboto",
width: "100%"
}}
>
<div style={{ fontSize: "35px", textAlign: "center", zIndex: 200 }}>
DUBAI UAE
</div>
</div>
</div>