我正在使用引导程序导航栏,我在导航栏中有我的链接。链接默认为左侧。我能够将链接移动到页面中心的唯一方法是使css为第一个列表项提供20em的边距。我想让它适应不同尺寸的显示器,但是如果显示器更大,它仍然会居中。以下是我的链接及其下方的CSS的bootstrap导航代码的一部分:
<nav class="navbar navbar-default">
<!--<div class="container">-->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Chompsta</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="margin-left"><a href="#">Chat anonymously</a></li>
<li><a href="#">Register for fame</a></li>
<li><a href="#">Search for topics</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><div id="points">172</div></li>
</ul>
</div><!-- /.navbar-collapse -->
<!--</div><!– /.container-fluid –>-->
</nav>
***
css
.margin-left { margin-left: 20em; }
答案 0 :(得分:2)
这可能会解决您的问题或让您朝着正确的方向前进。这将使您的主navbar-right
个链接居中,并使您的@media (min-width: 768px) {
.navbar .navbar-nav {
display: inline-block;
float: none;
vertical-align: top;
}
.navbar .navbar-collapse {
text-align: center;
}
}
保持在其中。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default">
<!--<div class="container">-->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button> <a class="navbar-brand" href="#">Chompsta</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="margin-left"><a href="#">Chat anonymously</a>
</li>
<li><a href="#">Register for fame</a>
</li>
<li><a href="#">Search for topics</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="#">
<div id="points">172</div>
</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
<!--</div><!– /.container-fluid –>-->
</nav>
&#13;
function getPixel(x, y, pixels) {
var out = [];
var pointer = pixels.offset + (pixels.stride[0] * x) + (pixels.stride[1] * y);
for(var i=0; i<4; i++) {
out.push(pixels.data[pointer + (pixels.stride[2] * i)]);
}
return out;
}
&#13;