2013-02-03 68 views
0

出于某种原因,我在示例图像中的元素将不会与页面的顶部对齐。我有一段时间没有使用HTML/CSS,但是我看不到任何编码方式会将矩形向下移动〜5px。 enter image description here为什么我的CSS元素不与网页顶部对齐?

我想实现这个页面上的酒吧:http://gradients.glrzad.com/

这里是我的代码。 HTML:

<!DOCTYPE "html"> 
<html> 
<head> 
<title>Mobile Site</title> 
<link href="mobileCSS.css" rel="stylesheet" type="text/css"> 
</head> 
<body> 
<div id="titleBar"> 
<strong>Coles Web</strong> 
</div> 
<div id="container"> 



</div> 
</body> 
</html> 

CSS:

@charset "utf-8"; 
/* CSS Document */ 

body{ 
    background-color:#666; 
} 
#container{ 
    width:auto; 

} 

#titleBar{ 
    position:fixed; 
    position:relative; 
    width:auto; 
    height:15px; 
    text-align:left; 
    font-family:Verdana, Geneva, sans-serif; 
    font-size:small; 
    color:#00FFFF; 
    background-color:#000; 
    box-shadow:0 3px 5px #333333; 
    border-bottom-left-radius:3px; 
    border-bottom-right-radius:3px; 
} 


.bubble{ 
    width:auto; 
    height: 40px; 
    position:relative; 
    border-spacing: 3px; 
    background-color:#0FF; 
    border-radius:3px; 
    font-family:Impact, Verdana, Geneva, sans-serif; 
    text-align:center; 

} 

提前感谢!

+5

将主体上的填充和边距设置为零。更好的是,使用CSS重置。 – j08691

+0

填充和边距现在为零,像魅力一样工作。谢谢j08691! – Cole

回答

2
body{ 
    background-color:#666; 
    padding: 0; 
    margin:0; 
} 
0

以下内容添加到#titlebar:

top:0; 
left:0; 

而且,你只能有一个位置。相对的或固定的。