把模态带到前面

时间:2016-07-05 11:33:20

标签: javascript modal-dialog

嘿,我正试图将这个模态带到页面上其他元素的前面。 我已经尝试过z-index:-1。

然后我想在adobe muse网站上实现这个代码,并使模态从组合框的选择中获得一个元素。 谢谢你的帮助。

  <!DOCTYPE html>
<html>
<head>
<style>
/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; front; /* Stay in place */  
     padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 600px; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
    z-index: 1; /* Sit on top */
}

/* Modal Content */
.modal-content {
    background-color: #00A1E0;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: 511px;
height: 250px;
}

/* The Close Button */
.close {
    color: #aaaaaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close:hover,
.close:focus {
    color: #blue;
    text-decoration: none;
    cursor: pointer;



</style>




<body>


<style>
div.background {

  border: 0px solid black;
div {
    background-color: #00A1E0;
    width: 511px;
}
}

div.transbox {
  margin: 30px;
  background-color: #00A1E0;
  border: 1px solid black;
opacity: 15%;
width: 511;
  filter: alpha(opacity=100); 
}

div.transbox p {
  margin: 5%;
  font-weight: bold;
  color: #000000;
}
</style>
</head>
<body>





<!-- Trigger/Open The Modal -->
<button id="myBtn">Add to shopping card
<div class="background">
  <div class="transbox">
<style>
#myBtn { color: #00A1E0; }
div.background {

  border: 0px #00A1E0;
div {
    background-color: #00A1E0;
    width: 511px;
}
}

div.transbox {
  margin: 30px;
  background-color: #FF530D;
 color: #00A1E0;
opacity: 80%;
width: 200;
  filter: alpha(opacity=100); 
}

div.transbox p {
  margin: 5%;
  font-weight: bold;
  color: #00A1E0;
}
#myModal { background: ; }

</style>
</button>

    </div>



</head>

<!-- The Modal -->
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">
    <span class="close">×</span>
    <p>you have added the classic business cards to the shopping cart</p>
  </div>

</div>

<script>
// Get the modal
var modal = document.getElementById('myModal');

// Get the button that opens the modal
var btn = document.getElementById("myBtn");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal
btn.onclick = function() {
    modal.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
    modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}

{

document.getElementById("resultSection").style.fontSize = "350%";



            document.getElementById("resultSection").innerHTML = "<H2></H2> " + result; 


                                               }
</script>
<style> #myBtn {  
     position: relative;



 font-size: 34px;

}
</style>
</body>
</html>

1 个答案:

答案 0 :(得分:2)

试试这个 - 修改评论以显示我已更改的内容

.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place front is invalid - may break your css so removed */  
    padding-top: 100px; /* Location of the box - don't know what this does?  If it is to move your modal down by 100px, then just change top below to 100px and remove this*/
    left: 0;
    right:0; /* Full width (left and right 0) */
    top: 0;
    bottom: 0; /* Full height top and bottom 0 */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
    z-index: 9999; /* Sit on top - higher than any other z-index in your site*/
}

您的.close:hoverfocus也有一个缺少的结束括号,并且您似乎在div.background内有嵌套样式 - 除非您使用的是css预处理器,是无效的css