尝试在父 div 内添加一个相对定位的 div。
前:
const FaceImage = ({image, boxs}) => {
return (
<div className="faceimage">
<img id="imgA" alt='' src={image}/>
<div className="bounding-box" style={{
top: boxs.top_row,
left: boxs.left_col,
bottom: boxs.bottom_row,
right: boxs.right_col
}}></div>
</div>
);
}
后:
const FaceImage = ({image, boxs}) => {
return (
<div className="faceimage">
<div className="relative">
<img id="imgA" alt='' src={image}/>
<div className="bounding-box" style={{
top: boxs.top_row,
left: boxs.left_col,
bottom: boxs.bottom_row,
right: boxs.right_col
}}></div>
</div>
</div>
);
}
CSS:
.relative {
position: relative;
}