![](/img/trans.png)
[英]How do I place a div on top of another div while maintaining alignment without using position:absolute?
[英]How to put a div on top of another div without using position absolute?
假設我有2張以邊距為中心的圖像,我需要以正確的方式放置它們而不使用position:absolute
,因為如果我使用它,則在放大/縮小時它們將向右/向左移動。
您可以使用:
img
{
position:relative;
margin: 0 auto;
clear:both;
display: block;
}
要么:
.centerme {
position: relative;
clear: both;
margin: 0 auto;
width: 50%; //or any other value
text-align:center
}
HTML示例:
<div class="centerme">
<img src="#" height="200px" alt="" />
</div>
<div class="centerme">
<img src="#" height="200px" alt="" />
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.