0

Hello I added a bottom navigation bar in HTML and CSS code on my webpage but I want have that centered on the bottom of the website any help and solutions is greatly appreciated I have attached screenshots of the HTML, CSS codes and the webpage of where I have my navigation bar currently in the left hand side thanks very much in advance.

.navbar {
  overflow: hidden;
  background-color: #333;
  position: fixed;
  bottom: 0;
  width: 100%
}

.navbar a {
  float: left;
  display: block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
  margin: 0px auto;
}

.navbar a:hover {
  background: #f1f1f1;
  color: black;
}
<div class="navbar">
  <a href="#">About</a>
  <a href="#">Contact</a>
  <a href="#">Facebook Page</a>
</div>

HTML navbar code

HTML navbar code

CSS navbar code

CSS navbar code

webpage navbar

webpage navbar

Mohammad Javad Noori
  • 1,187
  • 12
  • 23
  • Possible duplicate of [Center content in responsive bootstrap navbar](https://stackoverflow.com/questions/18777235/center-content-in-responsive-bootstrap-navbar) – Mohammad Javad Noori Feb 01 '18 at 08:19

4 Answers4

1

Just Replace your CSS code with below css code:

.navbar {
  overflow: hidden;
  background-color: #333;
  position: fixed;
  bottom: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;

}

.navbar a {
  color: #f2f2f2;
  text-align: center;
  display: inline-block;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
  margin: 0px auto;
}

.navbar a:hover {
  background: #f1f1f1;
  color: black;
}

and your HTML with this code:

<div class="navbar">
  <div class="navbar-inner">
     <a href="#">About</a>
     <a href="#">Contact</a>
     <a href="#">Facebook Page</a>
  </div>
</div>

Hope this code will work as you expect ..

Jawad Abdani
  • 337
  • 1
  • 9
0

Add to .navbar:

text-align:center;

Delete from .navbar a:

float: left;

Update in .navbar a:

display: inline-block;
Kloker
  • 499
  • 4
  • 14
0

body {margin:0;}

.navbar {
  overflow: hidden;
  background-color: #333;
  position: fixed;
  bottom: 0;
  width: 100%;
}

.navbar a {
  float: left;
  display: block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
}

.navbar a:hover {
  background: #f1f1f1;
  color: black;
}

.navbar a.active {
  background-color: #DDA0DD;
  color: white;
}

.main {
  padding: 16px;
  margin-bottom: 30px;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
</style>
</head>
<body>

<div class="navbar">
  <a href="#home" class="active">About</a>
  <a href="#news">Contact</a>
  <a href="#contact">Facebook page</a>
</div>

<div class="main">
  <h1>Bottom Navigation Bar</h1>
  <p>Some text some text some text.</p>
</div>

</body>
</html>
Husam Ebish
  • 4,893
  • 2
  • 22
  • 38
-1

How to center a nav-bar at the bottom of a page

How to center a nav-bar at the bottom of a page

Jin Lee
  • 3,194
  • 12
  • 46
  • 86