I don't know if this is what you intended, but if all you want is for a clickable background div with components on top of it that don't activate the onClick event of the background, then you could separate the background div from its children, for example:
import "./styles.css";
export default function App() {
return (
<div className="parent-div">
<div
className="div-style"
onClick={() => console.log("go to tweet page")}
></div>
<a href="#tweet-author">
<img
className="img-style"
src="https://www.pixsy.com/wp-content/uploads/2021/04/ben-sweet-2LowviVHZ-E-unsplash-1.jpeg"
onClick={() => console.log("go to tweet author")}
alt="Author"
/>
</a>
<h2 className="h2-style">Start editing to see some magic happen!</h2>
</div>
);
}
You can add styling to the div background, so it covers the whole container (or adjust the styling to match your preference, add display relative to the other elements to make them visible:
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.parent-div {
position: relative;
height: 200px;
padding: 15px;
margin: 15px;
}
.div-style {
background: url("https://i.pinimg.com/originals/0b/1b/04/0b1b0434864a51a9e607c6241c148090.jpg");
background-size: cover;
background-position: center;
position: absolute;
border-radius: 7px;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.img-style {
position: relative;
height: 50px;
width: 50px;
border-radius: 50%;
}
.h2-style {
position: relative;
}
Let me know if this is what you intended, if not please add a comment so I can adjust my answer accordingly.