![](/img/trans.png)
[英]How to put an image on top of a div (center horizontally but top vertically, in the middle)
[英]How to put image on the top of the div?
這是我的代碼
<div id="content_main2">
<div id="content_main2_left"><img src="../images/logo.png"></div>
</div>
的CSS
#content_main2
{
width:800px;
height:200px;
}
#content_main2_left
{
float:left;
width:300px;
height:240px;
margin-top:-40px;
-webkit-border-radius:15px;
-moz-border-radius:15px;
border-radius:15px;
background:#817339;
}
我的結果
bt我需要在div頂部顯示徽標。 我的意思是一半在#content_main2
div上,另一半在#content_main2_left
。 我該怎么做 ?
為圖像(而不是div)寫margin-top:-40px
。
更好地使用
position: absolute;
和不同的z-index
都
您可以嘗試使用負邊距。
對於圖像使用以下css
#logoimage
{
position: absolute;
bottom: xxpx;
}
用所需的像素替換xx 。
嘗試將此規則添加到樣式表中:
#content_main2_left img
{
position: relative;
left: 235px;
}
我對您希望它如何重疊感到困惑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.