Html 如何将图像放在div的顶部?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11151164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to put image on the top of the div?
提问by Prashobh
here is my code
这是我的代码
<div id="content_main2">
<div id="content_main2_left"><img src="../images/logo.png"></div>
</div>
css
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;
}
my result
我的结果
bt i need to display logo on top of the div. I mean half on #content_main2
div and another half on #content_main2_left
. how can i do it ?
bt 我需要在 div 顶部显示徽标。我的意思是一半在#content_main2
div 上,另一半在#content_main2_left
. 我该怎么做 ?
采纳答案by F0G
write margin-top:-40px
for image, not for div.
margin-top:-40px
为图像而写,而不是为 div写。
回答by Miqdad Ali
Better use
更好的使用
position: absolute;
and
different z-index
both
并且z-index
两者不同
回答by Miqdad Ali
You can try with negative margins.
您可以尝试使用负边距。
回答by Big McLargeHuge
Try adding this rule to your stylesheet:
尝试将此规则添加到您的样式表中:
#content_main2_left img
{
position: relative;
left: 235px;
}
I'm confused about how you want it to overlap though.
不过,我对您希望它如何重叠感到困惑。
回答by Muhammad Ummar
for image use the following css
对于图像使用以下css
#logoimage
{
position: absolute;
bottom: xxpx;
}
replace xxwith required pixels.
用所需的像素替换xx。