Mandar Sant Mandar Sant - 4 months ago 17
CSS Question

Solution for align bootstrap navigation(links) to the center

I am creating bootstrap site in which i have nav class which by default left side of the page but i want it to align it in the center ( i tried using align-text,align-itm then using bootstrap class row and col-md-4 but still no problem solved)

here is my code

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

Answer

use the bootstrap class row and use the second .class col-md-6 .col-md-offset-3

JSbin

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;

}
Comments