HTML Divs在放大/缩小时移动

时间:2014-03-16 00:09:45

标签: html css

当用户放大或缩小浏览器时,我的div正在移动,或者缩小了它的大小。我正在创建的网站只有在100%浏览器缩放时看起来很正常,这是标准的。

http://www.enlytn.me

处自行检查

这是我的代码,我希望这样做,这样当放大和缩小时div不会移动,它们保持彼此之间的距离,它们不重叠,它们保持相同的大小等。一般来说,一般网站有什么,当放大和缩小浏览器时,它们的div保持不变。

HTML -

<!DOCTYPE HTML>
<html>


<head>
      <title>Enlytn.me</title>
      <link rel='stylesheet' type='text/css' href='indexstyle03.css'/>
</head>

<body>
<script src="indexjs.js">
</script>



 <div class="banner">
  <div>
     <a href="http://enlytn.me"><p id="enlytn">e.</p></a>
  </div>
 </div>

 <div class="form">
     <h2>Sign in</h2>
      <input name='username' placeholder='Username' type='text'/>
      <input id='pw' name='password' placeholder='Password' type='password'/>
      <div class='remember'>
      <input checked='' id='remember' name='remember' type='checkbox'/>
      <label for='remember'></label>Remember me
      </div>
      <input type='submit' value='Sign in'/>
      <a class='forgot' href='#'>Forgot your password?</a>
      <a class='reg' href='#'Register</a>
 </div>

 <div class="anon">
     <h2>Continue as Anonymous</h2>
      <input name='anonymous' type='submit' value='Anonymous' />
 </div>

 <div class="gall">
      <h2>Current Affairs</h2>
 </div>



</body>


</html>

这是我的CSS

html {
background:url(Images/Background1.jpg) no-repeat center center fixed; 
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}

html, body { 
margin:0; 
padding:0; 
}


/*Banner font start*/
@font-face {
font-family:bannerfont;
src:url(fonts/SketchRockwell-Bold.ttf);
}

@font-face {
font-family:bannerfontreg;
src:url(fonts/hapole_marker.ttf);
}
/*Banner font end*/


@font-face {
font-family:loginfont;
src:url(fonts/sketchy.ttf);
}


/*Banner start*/
.banner{
position:absolute;
top:0;
left:0;
width:100%;
background-color:#373f42;
height:58px;


}
.banner #enlytn{
position:absolute;
color:#EEF3FF;
font-family:bannerfont;
font-size:75px;
top:-95px;
left:75px;
opacity:1;
} 


/*Banner end*/

.form {
width: 250px;
position: absolute;
top: 40%;
right: 10%;
margin: -184px 0px 0px -155px;
background: rgba(0,0,0,0.2);
padding: 20px 30px;
border-radius: 5px;
box-shadow: 0px 1px 0px rgba(0,0,0,0.3),inset 0px 1px 0px rgba(255,255,255,0.07)
}

.form h2 {
font-family: sans-serif;
color:#5EBA2C;
font-size: 15px;
font-weight: 600;
text-align: center;
margin-bottom: 10px;
}

.form a {
color: #5EBA2C;
text-decoration: none;

}

input[type="text"], input[type="password"] {
width: 250px;
padding: 25px 0px;
background: transparent;
border: 0;
border-bottom: 1px solid #5EBA2C;
outline: none;
color:#5EBA2C;
}
input[type=checkbox] {
display: none;
}

label {
display: block;
position: absolute;
margin-top: 2px;
width: 4px;
height: 4px;
border-radius: 50%;
background: #46485c;
content: "";
transition: all 0.3s ease-in-out;
cursor: pointer;
border: 3px solid #252730;
box-shadow: 0px 0px 0px 2px #46485c;
}

#remember:checked ~ label[for=remember] {
background: #b5cd60;
border: 3px solid #252730;
box-shadow: 0px 0px 0px 2px #b5cd60;
}


input[type="submit"] {
background: #b5cd60;
border: 0;
width: 250px;
height: 40px;
border-radius: 3px;
color: white;
cursor: pointer;
transition: background 0.3s ease-in-out;
}
input[type="submit"]:hover {
background: #16aa56;
}

.forgot {
margin-top: 30px;
display: block;
font-size: 11px;
text-align: center;
font-weight: bold;
}
.forgot:hover {
margin-top: 30px;
display: block;
font-size: 11px;
text-align: center;
font-weight: bold;
color: #5EBA2C;
}

.remember {
padding: 30px 0px;
font-size: 15px;
text-indent: 25px;
line-height: 15px;
font-family:sans-serif;
color: #5EBA2C;
}

::-webkit-input-placeholder {
color: #5EBA2C;
}

[placeholder]:focus::-webkit-input-placeholder {
transition: all 0.2s linear;
transform: translate(10px, 0);
opacity: 0;
}

.anon {
width: 250px;
position: absolute;
top: 85%;
right: 10%;
margin: -184px 0px 0px -155px;
background: rgba(0,0,0,0.2);
padding: 20px 30px;
border-radius: 5px;
box-shadow: 0px 1px 0px rgba(0,0,0,0.3),inset 0px 1px 0px rgba(255,255,255,0.07)
}

.anon h2 {
font-family: sans-serif;
color:#5EBA2C;
font-size: 15px;
font-weight: 600;
text-align: center;
margin-bottom: 10px;
}

.gall {
width: 250px;
position: absolute;
top: 40%;
right: 50%;
margin: -184px 0px 0px -155px;
background: rgba(0,0,0,0.2);
padding: 20px 30px;
border-radius: 5px;
box-shadow: 0px 1px 0px rgba(0,0,0,0.3),inset 0px 1px 0px rgba(255,255,255,0.07)
}

.gall h2 {
font-family: sans-serif;
color:#5EBA2C;
font-size: 15px;
font-weight: 600;
text-align: center;
margin-bottom: 10px;
}

感谢您提供的任何帮助,我将永远感激,因为我觉得在此问题得到解决之前我的网站开发无法取得进展。

1 个答案:

答案 0 :(得分:0)

你不能使用固定像素大小,并且当画布收缩时你的元素不会移动。如果他们不合适,他们会去哪里?

不是将大小声明为固定像素,而是使用与父元素相对大小的ems设置它们。 1em =父母的100%。

http://www.w3schools.com/cssref/css_units.asp