【问题标题】:Div positioning over another divdiv 定位在另一个 div 上
【发布时间】:2013-11-13 18:59:57
【问题描述】:

我正在尝试将包含可点击图片的 div 放在包含背景的 div 上。但是,这种情况一直在发生:

http://gyazo.com/2144dfe91b46898e125787b2f5249542

它在图片下方,我不明白为什么。

这是我的代码:

!DOCTYPE html>
<html>
<head>
<title>SlammedPK</title>
<link rel="shortcut icon" href="dragonclaws.png" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="style.css"> 
    <style type"text/css">
    #title{
        height:100%;
        width:100%;
        display:inline-block;
    }
    #forum{
        height:10%;
        width:10%;
        background-image:forum.png;
        display:block;
    }
    </style>
</head>
</body>
<div id="container">
    <div id="title" style="position:relative" alt="title">
    <img src='fulltitle.png' style='width:100%;height:100%' alt='[]' />
    </div>
    <div id="forum" style="position:absolute" alt="forum">
    <A HREF="http://google.com"><IMG SRC="forum.png" ALT="forum"></A>
    </div>
</div>
</body>
</html>

如果你能帮忙,那就太好了。

【问题讨论】:

    标签: css image position


    【解决方案1】:

    首先,你的背景图片格式不正确,你需要background-image: url(forum.png); 和#title 一样的东西。我不知道你为什么给它一个背景图片,虽然你里面还有一个img

    至于你的问题,你需要给#containerposition:relative;或position:absolute。绝对定位的元素必须是子元素或相对定位的父元素

    【讨论】:

    • 我将它添加到论坛 css 中,并添加了 'background-image:fulltile.png;'到#title。但什么都没有改变?
    • @FinnBeckett-hester 我很笨,我更新了我的解决方案。它现在应该可以解决您的问题
    • 感谢您的帮助,非常感谢!祝你有美好的一天!
    • @FinnBeckett-hester 如果答案满足您的问题,您可以在答案左侧标记复选标记以表明它是正确的并表明问题已被回答
    【解决方案2】:

    我制作了这个 JsFiddle:http://jsfiddle.net/2c7eQ/

    使#forum 和#title 都是position: absolute

    HTML:

    <div id="container">
        <div id="title">
        div1
        </div>
        <div id="forum">
        div2
        </div>
    </div>
    

    CSS:

    #title{
            position: absolute;
            border: 1px solid;
            background-color: blue;
            height:100%;
            width:100%;
    }
    #forum{
            position: absolute;
            left: 100px;
            top: 100px;
            border: 1px solid;
            background-color: green;
            height:10%;
            width:10%;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-10
      • 2013-07-11
      • 2012-05-08
      • 1970-01-01
      • 1970-01-01
      • 2012-04-24
      • 1970-01-01
      • 2014-11-12
      相关资源
      最近更新 更多