如何将图片放在 div 上方?

4

这是我的代码

<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; 
}

我的结果

在此输入图片描述

但我需要在div的顶部显示标志。我是说一半在#content_main2 div上,另一半在#content_main2_left上。我该怎么做?

5个回答

4
为图片添加 margin-top:-40px,而不是为 div 添加。

2
您可以尝试使用负边距来实现。

1

最好使用

position: absolute;

和不同的z-index两者都


0

对于图片,请使用以下 CSS

#logoimage
{
   position: absolute;
   bottom: xxpx;
}

用所需像素替换xx


0

尝试将此规则添加到您的样式表中:

#content_main2_left img
{
    position: relative;
    left: 235px;
}

我对于你想要它如何重叠感到困惑。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接