Div下拉菜单覆盖其他内容

时间:2017-09-03 20:18:48

标签: javascript html css

我试图制作它,以便当您点击div中的图标时,会出现一个下拉框,显示并覆盖div的内容。但是现在,我的下拉框只是简单地推下了div的内容,而不是覆盖它。在浏览了这个网站上的类似问题之后,我几乎可以肯定问题是我的CSS必须要做一些元素位置:相对和其他元素位置:绝对,但我已经玩了一段时间了似乎无法让它正常工作。下面是我的代码的干净版本(没有各种位置尝试)。

相关的CSS代码是:

#ideas_box {
    display: inline-block;
    *display: inline;
    background-color: white;
    min-width: 1110px;

    overflow: hidden;
    margin: 0px 20px 20px 20px;

    border: solid 1px #6a6a6a;
    box-shadow: 3px 3px 3px #cecdcd;
    -moz-box-shadow: 3px 3px 3px #cecdcd;
    -webkit-box-shadow: 3px 3px 3px #cecdcd;
}

#ideas_box_majority_bar_green{
    display: inline-block;
    *display: inline;
    float: left;
    width: 10px;
    margin-bottom: -1000px;  /* for making green bar as large as parent div */
    padding-bottom: 1000px; /* for making green bar as large as parent div */
    background-color: #a8fba6;
}

#ideas_box_main_content {
    display: inline-block;
    *display: inline;
    float: left;
    width: 100%;
    margin: 10px 0px 10px 20px;
}

#ideas_box_top {
    display: inline-block;
    *display: inline;
    float: left;
    width: 100%;
    overflow: hidden;
}

#ideas_box_top_image {
    display: inline-block;
    *display: inline;
    float: left;
    width: 60px;
}

#ideas_box_top_titlebar {
    display: inline-block;
    *display: inline;
    float: left;
}

#ideas_box_top_titlebar_title {
    display: inline-block;
    *display: inline;
    float: left;
    width: 100%;
    padding: 5px 0px 0px 0px;
    color: #060708;
    font-family: "Arial";
    font-size: 150%;
}

#ideas_box_top_titlebar_postInfo {
    display: inline-block;
    *display: inline;
    float: left;
    width: 100%;
    color: #363636;
    font-family: "Arial";
    font-style: italic;
    font-size: 80%;
}

#ideas_box_top_iconBar {
    display: inline-block;
    *display: inline;
    float: right;
    width: 150px;
    padding-right: 30px;
}

#ideas_box_top_iconBar_comment {
    display: inline-block;
    *display: inline;
    float: left;
    width: 50px;
    text-align: center;
    color: #060708;
    font-family: "Arial";
}

#ideas_box_top_iconBar_thumbsUp {
    display: inline-block;
    *display: inline;
    float: left;
    width: 50px;
    text-align: center;
    color: #060708;
    font-family: "Arial";
}

#ideas_box_top_iconBar_thumbsDown {
    display: inline-block;
    *display: inline;
    float: left;
    width: 50px;
    text-align: center;
    color: #060708;
    font-family: "Arial";
}

#ideas_box_content {
    float: left;
    overflow: hidden;
    color: black;
    font-family: "Arial";
    font-size: 100%;
    margin-right: 40px;
}


#comments_dropDown_box_point {
    display: none;

    width: 20px;
    height: 14px;
    position: relative;

    left: 13px;
    top: 3px;

    background:url('../img/box_point.png'); 

    z-index: 10;
}

#comments_dropDown_box {
    display: none;

    position: relative;
    width: 70px;
    color: black;
    background-color: white;
    border: solid 1px #C2C2C2;
    overflow: auto;

    left: -13px;
    top: 2px;

    z-index: 9;

    border-radius: 6px;
    -moz-border-radius: 6px;
    -webkit-border-top-right-radius:6px;
    -webkit-border-top-left-radius:6px;
    -webkit-border-bottom-left-radius:6px;
    -webkit-border-bottom-right-radius:6px;

    border: solid 1px #C2C2C2;
    box-shadow: 3px 3px 3px #cecdcd;
    -moz-box-shadow: 3px 3px 3px #cecdcd;
    -webkit-box-shadow: 3px 3px 3px #cecdcd;
}

#comments_dropDown_box .comments_dropDown_row {
    float: left;
    width: 100%;
    overflow: auto;
    text-align: center;
    padding: 5px 0px 5px 0px;
    font-style: italic;
}

#comments_dropDown_box .dropDown_divider {
    float: left;
    width: 100%;
    height: 2px;
    background-color: #dfdede;
}

HTML代码为:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="application/xml; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<html lang="en">
<head>

    <!-- JQUERY -->
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script src="js/scripts_ideaboard.js"></script>

    <!-- CSS -->
    <link type="text/css" href="css/ideaboard.css" rel="stylesheet"  media="screen">

</head>

<body>

    <!-- LIST -->
    <div id="ideas_box">
        <div id="ideas_box_majority_bar_green"></div>
        <div id="ideas_box_main_content">
            <div id="ideas_box_top">
                <div id="ideas_box_top_image"></div>
                <div id="ideas_box_top_titlebar">
                    <div id="ideas_box_top_titlebar_title">Test</div>
                    <div id="ideas_box_top_titlebar_postInfo">Test on Aug 09 2017, 08:37:58pm</div>
                </div>
                <div id="ideas_box_top_iconBar">
                    <div id="ideas_box_top_iconBar_comment">
                        <img src="img/comments.jpg" style="height: 40px; width: 40px;"><br>
                        +8
                        <!-- display drop down for comments -->
                            <div id="comments_dropDown_box_point"></div>
                            <div id="comments_dropDown_box">
                                <div class="comments_dropDown_row">
                                    User1
                                </div>
                                <div class="dropDown_divider"></div>
                                <div class="comments_dropDown_row">
                                    User2
                                </div>
                                <div class="dropDown_divider"></div>
                                <div class="comments_dropDown_row">
                                    User3
                                </div>
                            </div>
                        <!-- END display drop down for comments -->
                    </div>
                    <div id="ideas_box_top_iconBar_thumbsUp">
                        <img src="img/like.jpg" style="height: 40px; width: 40px;"><br>
                        +3
                    </div>
                    <div id="ideas_box_top_iconBar_thumbsDown">
                        <img src="img/dislike.jpg" style="height: 40px; width: 40px;"><br>
                        -2
                    </div>
                </div>
            </div>
            <div id="ideas_box_content">
            This is a test
            </div>
        </div>
    </div>

    <!-- LIST -->
    <div id="ideas_box">
        <div id="ideas_box_majority_bar_green"></div>
        <div id="ideas_box_main_content">
            <div id="ideas_box_top">
                <div id="ideas_box_top_image"></div>
                <div id="ideas_box_top_titlebar">
                    <div id="ideas_box_top_titlebar_title">Test</div>
                    <div id="ideas_box_top_titlebar_postInfo">Test on Aug 09 2017, 08:37:58pm</div>
                </div>
                <div id="ideas_box_top_iconBar">
                    <div id="ideas_box_top_iconBar_comment">
                        <img src="img/comments.jpg" style="height: 40px; width: 40px;"><br>
                        +8
                        <!-- display drop down for comments -->
                            <div id="comments_dropDown_box_point"></div>
                            <div id="comments_dropDown_box">
                                <div class="comments_dropDown_row">
                                    User1
                                </div>
                                <div class="dropDown_divider"></div>
                                <div class="comments_dropDown_row">
                                    User2
                                </div>
                                <div class="dropDown_divider"></div>
                                <div class="comments_dropDown_row">
                                    User3
                                </div>
                            </div>
                        <!-- END display drop down for comments -->
                    </div>
                    <div id="ideas_box_top_iconBar_thumbsUp">
                        <img src="img/like.jpg" style="height: 40px; width: 40px;"><br>
                        +3
                    </div>
                    <div id="ideas_box_top_iconBar_thumbsDown">
                        <img src="img/dislike.jpg" style="height: 40px; width: 40px;"><br>
                        -2
                    </div>
                </div>
            </div>
            <div id="ideas_box_content">
            This is a test
            </div>
        </div>
    </div>

</body>

JS代码是:

$(document).ready(function() {

    $("#ideas_box_top_iconBar_comment").click(function()
    {
        $("#comments_dropDown_box").toggle();
        $("#comments_dropDown_box_point").toggle();
    });


});

现场版本在这里:http://php.net/manual/en/function.in-array.php(点击第一篇文章中的评论图标)

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:0)

正如我在评论中提到的那样 - 你将需要对其余的代码进行更多的重新格式化,以使其完全符合您的要求,但我有一些时间,所以我想我会告诉你如何制作整个position: relativeposition: absolute

首先,我将所有ID更改为类并删除了您的父元素上的overflow: hidden - 如果处于活动状态,则无法从div中弹出“工具提示”。那当然 - 破坏了你的绿线如何工作,但它允许我们让工具提示工作。

之后,我将position: relative添加到您的.ideas_box_top_iconBar_comment,因为这将是父工具提示箭头的类。

然后我将工具提示箭头&amp; .comments_dropDown_boxWrapper中的菜单,并具有以下css:

.comments_dropDown_boxWrapper { 
  position: absolute;
  top: 100%;
  left: 0;
  display: none;
}

然后在更改了javascript以使用新的包装器类之后,我们让它工作了!

这是jsfiddle所以你可以看到它的全部动作。这不是您正在做的事情的逐步解决方案,但我希望它能够帮助您自己解决问题。

的jsfiddle: https://jsfiddle.net/yt8Ltu31/

答案 1 :(得分:0)

将其设为position: absolute,然后执行z-index: 1