我使用了一些源代码,它在click事件中显示了一个模态视图框。在在线演示中,它运行良好,但在我的网页上,他的框加载有点扭曲,模式框位于网站徽标和网站标题文本后面。
我到目前为止在网上遇到的文章告诉我尝试z-index方法,并将所有涉及的元素设置为相对,但是这没有用,因为它进一步扭曲了我的其余页面元素。
我在这个jsFiddle:https://jsfiddle.net/a0ht7y51/
中复制了这个问题此处也张贴相关代码:
HTML:
<div id="header">
<img id="headerBackground" src="siteImages/tiltchair.jpg">
<img id="Logo" onclick="document.getElementById('id01').style.display='block'" align="middle" src="siteImages/final.png" alt="Logo">
<img id="Text" align="middle" src="siteImages/TWText.png" alt="Logo">
<form class="modal-content animate" action="action_page.php">
<div class="imgcontainer">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">×</span>
</div>
<div class="container">
<label><b>Username</b></label>
<input type="text" class="input-txt" placeholder="Enter Username" name="uname" required>
<label><b>Password</b></label>
<input type="password" class="input-txt" placeholder="Enter Password" name="psw" required>
<button type="submit">Login</button>
<input type="checkbox" checked="checked"> Remember me
</div>
<span class="psw">Forgot <a href="#">password?</a></span>
</form>
CSS:
.input-txt{
width: 100%;
padding: 20px 10px;
background: $blue;
border: none;
font-size: 1em;
color: white;
border-bottom: 1px dotted rgba(250, 250, 250, .4);
@include box-sizing(border-box);
@include placeholder(lighten($blue, 10%));
@include transition(background-color .5s ease-in-out);
&:focus{
background-color: darken($blue, 30%);
}
}
p{
font-size:16px
text-align: left;
}
h1 {
font-size:16px
}
/* CSS for modal */
/* Full-width input fields */
input[type=text], input[type=password] {
width: 33%;
padding: 12px 20px;
margin: 8px 0;
display: block;
border: 1px solid #ccc;
box-sizing: border-box;
align-items: center;
}
/* Set a style for all buttons */
button {
background-color: #1dacf9;
color: white;
padding: 1px 2px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 33%;
}
/* Extra styles for the cancel button */
.cancelbtn {
width: auto;
padding: 10px 18px;
background-color: #f44336;
}
/* Center the image and position the close button */
.imgcontainer {
text-align: center;
margin: 24px 0 12px 0;
}
img.avatar {
width: 40%;
border-radius: 50%;
}
.container {
padding: 6px;
}
span.psw {
float: right;
padding-top: 16px;
}
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 10; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* 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 */
padding-top: 60px;
height: 100vh;
border-radius: 20px;
}
/* Modal Content/Box */
.modal-content {
background-color: #fefefe;
margin: 5% auto 15% auto; /* 5% from the top, 15% from the bottom and centered */
border: 1px solid #888;
width: 66%; /* Could be more or less, depending on screen size */
height: 66vh;
border-radius: 20px;
}
/* The Close Button (x) */
.close {
position: relative;
margin: 2% auto 95% auto;
color: #000;
font-size: 35px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: red;
cursor: pointer;
}
/* Add Zoom Animation */
.animate {
-webkit-animation: animatezoom 0.6s;
animation: animatezoom 0.6s
}
@-webkit-keyframes animatezoom {
from {-webkit-transform: scale(0)}
to {-webkit-transform: scale(1)}
}
@keyframes animatezoom {
from {transform: scale(0)}
to {transform: scale(1)}
}
/* Change styles for span and cancel button on extra small screens */
@media screen and (max-width: 300px) {
span.psw {
display: block;
float: none;
}
.cancelbtn {
width: 100%;
}
}
#headerBackground {
position: fixed;
width: 100%;
top: 0;
left: 0;
height: 100vh;
z-index: -10;
}
#TWLogo {
transform: translateZ(1px);
display: block;
margin-top: 5%;
margin: 0 auto;
cursor: pointer;
background-attachment: fixed;
padding-top: 50px;
padding-bottom: 50px;
width:150px;
height:125px;
transition: all .2s ease-in-out;
background-position:center;
z-index: -1;
}
#Logo:hover { transform: scale(1.1); }
#Text {
display: block;
margin: 0 auto;
padding-top: 80px;
padding-bottom: 50px;
width:355px;
height:125px;
transform: translateZ(30px);
background-position:center;
z-index: -1;
}
所以我对CSS的最低限度的知识阻止了我看到什么是一个简单的解决方案,谁能看到它?