I’m using the following code to try and place a "Copy" button over the upper right hand corner of an image :
<div className="itemImg">
<Button icon={<MdContentCopy />} style={{float: 'right'}} onClick={(e) => {copyItem(props.item.name)}} />
<Image
className="itemImg"
src={"/api/feed/"+props.feed+"/"+props.item.name}
preview={false}
/>
</div>
If the block is a , i.e. not an image, it works as expected, but for some reason, <Image>
is having an issue, see below. The "Copy" icon should be placed atop the image because of float: right
Our good friend ChatGPT recommends not using float
and rely on flex layout to do this. Not a big deal and it actually provided the solution, but I’d rather have minimal code and CSS over what antd/react provides natively.
2
Answers
give the container a
position: absolute
and awidth: min-content
so it fits the image width.After that you can position the button with
position: absolute
To solve that you need to create a container with
position: relative
and inside the container, you add your image and the button. but the button must have aposition: absolute
and add right and top values.I have added a snippet, you can change that to your react code using your components it will work the same.