我有一个基本的布局,我试图实现。我有一个带有徽标的.container类,左边有一个徽标,然后我想要一个浮动到右边和容器顶部的bootstrap导航栏,它似乎是正确浮动的" pull-right& #34; " navbar-nav"上的课程带引导程序的类,但它位于品牌标识下面,我不能为我的生活弄清楚为什么或如何正确对齐它。
无论如何,这是html ....
<html lang= "en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
<link type="text/css" rel="stylesheet" href="style.css">
</head>
<body>
<div class= "container">
<header class = "headerWrap">
<div class = "row">
<div class ="brand"></div>
<div class = " userNav col-sm-8 col-sm-offset-4">
<nav class = "navbar navbar-default">
<ul class= "nav navbar-nav pull-right">
<li><a href= "#">Home</a></li>
<li><a href= "#">Contact Us</a></li>
<li><a href= "#">Sign In</a></li>
<li><a href= "#">Cart</a></li>
<li><a href= "#">Location + Directions</a></li>
<li><a href= "#">Who We Are</a></li>
<li><a href= "#">Alumni Network</a></li>
</ul>
</nav>
</div>
</div>
</header>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</body>
</html>
继承人的CSS:
$font-color: white;
body {
background-color: black;
}
.headerWrap {
width: 100%;
height: 250px;
}
.brand {
background-image:url(img/Screen%20Shot%202015-10-25%20at%2010.13.40%20PM.png);
background-size: 100%;
float: left;
background-repeat: no-repeat;
width: 250px;
height: 100px;
}
.userNav {
float: right;
}
.navbar-default {
background-color: transparent;
border: none;
}
.navbar-default .navbar-nav>li>a{
color: $font-color;
}
我错过了什么?
答案 0 :(得分:1)
这只是因为您已将col-sm-offset-4
类添加到userNav
元素中。删除它,一切都将按预期工作。当您保持col-sm-offset-4
课程时会发生什么,它会完全视为element
需要12
网格。由于brand - logo
已经移动了4个网格,并且框架无法在同一12
中分配row
网格,因此会将其移至新的row
。所以不需要再次给offset
。只需更改元素的类,如下所示:
<div class ="userNav col-sm-8"> <!--remove col-sm-offset-4 from here-->
只为 DEMO