"logo"和"navbar"在标题内的位置



这已经让我耗了好几个小时了:'(谁能帮我把logo和导航条放在页眉里面??

我试图把"logo"内的头(左侧)和"导航栏"内的头(右侧),但即使我尝试了许多不同的属性,我的导航栏总是在头容器外…

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;
}

你的ul有margin and padding:)

工作小提琴

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的左右填充。

更新小提琴下面是修改后的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;
}

此处:

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

也稍微清理了你的代码:

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

最新更新