在不使用絕對定位或更改標記的情況下,我能想到的唯一方法是使用CSS網格并使兩個元素占用同一單元格。 .imgCon { display: flex; width: 95%; height: 95%; margin: auto; background-color: blue; display: grid; } .imgCon img { width: 95.5%; height: 95%; margin: auto; border-radius: inherit; grid-column-start: 1; grid-row-start: 1; } .iconCon { display: flex; justify-content: center; align-items: center; width: 4rem; height: 4rem; margin: auto; color: #ffffff; border-radius: 50%; background-color: #000000; grid-column-start: 1; grid-row-start: 1; } <div class="imgCon"> <img src="https://www.vitalground.org/wp-content/uploads/2021/11/Bart-the-Bear-II--e1637176991443.jpg" /> <!--center this--> <div class="iconCon"> C </div> </div>
在不使用絕對定位或更改標記的情況下,我能想到的唯一方法是使用CSS網格并使兩個元素占用同一單元格。