2013-06-19 37 views
0

这是我的命了几个小时已经定位:“(任何人都可以帮我定位头???“标志”和“导航栏”内头

我试图把里面的标志和导航栏标题内的“logo”(左侧)和标题内的“navbar”(右侧),但即使我尝试了许多不同的属性,但我的导航栏始终位于标题容器之外...标题应该固定。

http://jsfiddle.net/L7kPu/10/

<header> 
     <a href="#" id="logo">Logo</a> 

        <ul id="nav" class="nav"> 
         <li><a href="#home">Home</a></li> 
         <li><a href="#about">About</a></li> 
         <li><a href="#services">Services</a></li> 
         <li><a href="#portfolio">Portfolio</a></li> 
         <li><a href="#contact">Contact</a></li> 
        </ul> 

</header> 
<link href='http://fonts.googleapis.com/css?family=Roboto+Slab:400,700' rel='stylesheet' type='text/css'> 

html, body{ 
    margin:0px; padding:0px; height: 100%; } 

section { 
    height: 100%; 
} 

header{ 
    z-index: 1; 
    position:fixed; 
    width:100%; 
    background:rgba(0,0,0,0.1); 
} 

header ul{ 
    float:right; 

} 

header ul li{ 
    display: inline; 
    float:left; 

} 
header a{ 
    color:white; 
    background:rgba(0,0,0,0.1); 
    display:inline-block; 
    padding:0px 30px; 
    height:60px; 
    line-height:60px; 
    text-align:center; 
    font-family: 'Roboto Slab', serif; 
    text-decoration:none; 
    text-transform:uppercase; 
    letter-spacing:2px; 
    font-weight:700; 
} 

回答

4

ul有margin和padding :)

Working Fiddle

header ul{ 
    float:right; 
    padding: 0; 
    margin: 0; 
} 

header ul li{ 
    display: inline; 
    float:left; 
} 
header a{ 
    color:white; 
    background:rgba(0,0,0,0.1); 
    display:inline-block; 
    padding:0px 25px; 
    height:60px; 
    line-height:60px; 
    text-align:center; 
    font-family: 'Roboto Slab', serif; 
    text-decoration:none; 
    text-transform:uppercase; 
    letter-spacing:2px; 
    font-weight:700; 
} 

我也改变了左右填充在header a对小提琴的缘故。

+0

我正要回答同样的事情! –

+0

太棒了!谢谢你和所有其他人缓解我的头痛!非常感谢! –

+1

没问题!很高兴我们可以帮助:) – rogMaHall

1

这里:

header ul 
{ 
float:right; 
    margin: 0; 
} 

header ul li 
{ 
display: inline; 
float:left; 
margin: 0; 
} 

而且清理你的代码一点点:

http://jsfiddle.net/L7kPu/17/

2

Updated Fiddle 这里是你的代码修改CSS:

#logo { 
    float: left; 
    position: aboslute; 
} 
#nav { 
    white-space: nowrap; 
    margin-top: 0; 
    margin-right: 0; 
} 
header { 
    z-index: 1; 
    position:fixed; 
    width:100%; 
    background:rgba(0, 0, 0, 0.1); 
    height: 60px; 
} 
+0

感谢您的帮助!什么是白色空间:nowrap;财产吗???从来没有听说过... –

+1

当页面的宽度小于导航宽度时,可以防止“包装”框在另一个下面。 –

+0

我注意到确切的事情正在发生。但即使使用'nowrap'属性也会发生同样的情况?如果有人打算在像手机这样的小屏幕设备上浏览我的页面,这是一个问题吗? –