我正在创建bootstrap网站,其中我有导航类,默认情况下左侧页面,但我希望它在中心对齐(我尝试使用align-text,align-itm然后使用bootstrap类行和col -md-4但仍未解决问题)
这是我的代码
<html>
<head>
<title>Landing Page</title>
<link rel="stylesheet" type="text/css" href="MylandingSS.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity= "sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet"/>
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top">
<!----------------HEADER------------------------------>
<div class="navbar-header navbar-brand header"><h1 class="navbarheader">IamMandar</h1></div>
<!------------------LINKS----------------------------------->
<div class="row">
<div class="col-md-4">
<ul class="nav nav-pills "><!---------to be centered------------->
<li><a href="">Page 1</a></li>
<li><a href="">Page 2</a></li>
<li><a href="">Page 3</a></li>
</ul>
</div>
</div>
</body>
</html>
CSS
@charset "utf-8";
body{
margin:0;
padding:0;
}
.navbar.navbar-default{
background-image:none;
background-color:rgba(89,63,127,0.79);
border:none;
}
.navbarheader{
color:#FFFFFF;
margin-top:-10px;
font-family: 'Lobster', cursive;
}
.nav ul{
color:#FFFFFF;
}
答案 0 :(得分:1)
使用中心区类
<div class="row">
<ul class="nav nav-pills center-block ">
<li><a href="">Page 1</a></li>
<li><a href="">Page 2</a></li>
<li><a href="">Page 3</a></li>
</ul>
</div>
或者尝试使用文本中心我不是专家但是试试这个:)
答案 1 :(得分:0)
使用引导类row
并使用第二个.class col-md-6
.col-md-offset-3
<强> HTML 强>
<html>
<head>
<title>Landing Page</title>
<link rel="stylesheet" type="text/css" href="MylandingSS.css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity= "sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet"/>
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top">
<!----------------HEADER------------------------------>
<div class="navbar-header navbar-brand header"><h1 class="navbarheader">IamMandar</h1></div>
<!------------------LINKS----------------------------------->
<div class="row">
<div class="col-md-6 col-md-offset-3">
<ul class="nav navbar-nav">
<li><a href="">Page 1</a></li>
<li><a href="">Page 2</a></li>
<li><a href="">Page 3</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
<强> CSS 强>
@charset "utf-8";
/* CSS Document */
body{
margin:0;
padding:0;
}
.navbar.navbar-default{
background-image:none;
background-color:rgba(89,63,127,0.79);
border:none;
}
.navbarheader{
color:#FFFFFF;
margin-top:-10px;
font-family: 'Lobster', cursive;
}
.nav,.navbar-nav{
font-size:15px;
color:white;
}
答案 2 :(得分:0)
这是codepen
的 HTML 强>
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<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="#">Brand Logo</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="pull-left"><a href="#">Dashboard</a></li>
<li class="active"><a href="#">Stories</a></li>
<li><a href="#">Videos</a></li>
<li><a href="#">Photos</a></li>
<li class="social pull-right"><a href="#">Social Links</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<强>的CSS:强>
.navbar-nav {
width: 100%;
text-align: center;
}
.navbar-nav > li {
float: none;
display: inline-block;
}
答案 3 :(得分:0)
在父text-align: center
上声明.nav
,然后在嵌套float
元素上取消li
,同时使用自定义css规则声明display: inline-block
,将对齐列表项目中心。
<强> CSS 强>
.nav.nav-pills>li {
display: inline-block;
float: none;
}
ul.nav.nav-pills {
text-align: center;
}
body{
margin:0;
padding:0;
}
.navbar.navbar-default{
background-image:none;
background-color:rgba(89,63,127,0.79);
border:none;
}
.navbarheader{
color:#FFFFFF;
margin-top:-10px;
font-family: 'Lobster', cursive;
}
.nav ul{
color:#FFFFFF;
}
.nav.nav-pills>li {
display: inline-block;
float: none;
}
ul.nav.nav-pills {
text-align: center;
}
&#13;
<html>
<head>
<title>Landing Page</title>
<link rel="stylesheet" type="text/css" href="MylandingSS.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity= "sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet"/>
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top">
<!----------------HEADER------------------------------>
<div class="navbar-header navbar-brand header"><h1 class="navbarheader">IamMandar</h1></div>
<!------------------LINKS----------------------------------->
<div class="row">
<div class="col-md-6 col-md-offset-3">
<ul class="nav nav-pills">
<li><a href="">Page 1</a></li>
<li><a href="">Page 2</a></li>
<li><a href="">Page 3</a></li>
</ul>
</div>
</body>
</html>
&#13;
也可以将徽标标记移动到与导航相同的行并相应地调整列。只需使用它,你可能会发现一个布局,需要更少的自定义样式,并保持更好的响应式布局。