2011-09-03 127 views
0

我做了一個小樣本網站,我只是想知道:爲什麼我的元素會移位?

爲什麼當我調整窗口大小時,我的元素會移位? 有沒有辦法阻止它?

的index.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Clean Layout Demo</title> 
<link href="css/cleanLayout.css" rel="stylesheet" type="text/css" /> 
</head> 
<body><center> 
<div id="header"> 
Famous Quotes 
</div><!-- end #header --> 
<div id="menu"> 
<a href="#">Home</a> | <a href="icons.html">Icons</a> 
</div><!-- end #menu --> 
<div id="content" style="height:auto;"><br /> 
Famous Quotes<br /><br /><hr noshade="noshade" /><br /> 
"Be who you are and say what you feel, because those who mind don't matter, and those who matter don't mind."<br /> 
- Dr. Seuss<br /><br /><hr noshade="noshade" /><br /> 
"A person who never made a mistake, never tried anything new."<br /> 
- Albert Einstein<br /><br /><hr noshade="noshade" /><br /> 
"Shoot for the moon. Even if you miss, you'll land among the stars."<br /> 
- Brian Litrell<br /><br /><hr noshade="noshade" /><br /> 
"Obstacles are things a person sees when he takes his eyes off the goal."<br /> 
- E. Joseph Cossman<br /><br /> 
</div><!-- end #content --> 
</center></body> 
</html> 

這是主要的網頁代碼

這是CSS:

@charset "utf-8"; 
@font-face { 
    font-family: Clean_Layout; 
    src:url(../fonts/GeosansLight.ttf) 
} 

html { 
    background-color: #CCC; 
} 

#header { 
    font-family: Clean_Layout; 
    font-size:64px; 
    text-align:center; 
    color:#333; 
    background: #999; 
    border:2px solid #666; 
    border-radius:16px; 
    -moz-border-radius:16px; 
    -webkit-border-radius:16px; 
    padding-top:22px; 
    padding-bottom:0; 
    width:600px; 
    height:100px; 
    margin-bottom:5px; 
} 

#menu { 
    font-family: Arial, Helvetica, sans-serif; 
    font-size:13px; 
    text-align:center; 
    color:#333; 
    width:500px; 
    background-color:#999; 
    border:1px solid #666; 
    -moz-border-radius:3px; 
    -webkit-border-radius:3px; 
    border-radius:3px; 
    margin-top:3px; 
    margin-bottom:5px; 
    padding-top:1px; 
padding-bottom:1px; 
} 

#menu a:link { 
    text-decoration:none; 
    color:#333; 
} 

#menu a:visited { 
    color:#333; 
} 

#menu a:hover { 
    color:#222; 
} 

#menu a:active { 
    color:black; 
} 

#content { 
    font-family:Clean_Layout; 
    font-size:24px; 
    color:#333; 
    background: #999; 
    border:3px solid #666; 
    border-radius:16px; 
    -moz-border-radius:16px; 
    -webkit-border-radius:16px; 
    width:825px; 
    overflow:auto; 
    padding-top:5px; 
    padding-bottom:5px; 
    padding-left:10px; 
    padding-right:10px; 
    margin-bottom:50px; 
} 

hr { 
    width:120px; 
    color:#666; 
} 

希望的代碼可以幫助

+4

你可以張貼一些代碼或您網站的鏈接? –

+0

你使用浮動嗎? – McArthey

+0

永遠不要重新調整您的瀏覽器窗口! –

回答

1

這裏是頁的小提琴:

http://jsfiddle.net/jasongennaro/rFESw/

你的頁面上的元素時,頁面被調整移動,因爲你已經使用

<body><center>

居中頁面。

但是,這是當你的頁面流暢時會發生什麼。

如果你想要的元素是靜態的,你需要給他們absolutefixed職位。

這裏的定位體面的概述:http://www.alistapart.com/articles/css-positioning-101/

+0

謝謝,這真的有幫助! – runizgozilla

+0

很有幫助,@runizgozilla。歡迎來到SO!如果這回答了問題,請單擊答案旁邊的複選標記以讓其他人知道問題已解決。 –

相關問題