0

I have a heading inside a navigation like below I am trying to align the Heading to the center of navigation.

<nav class="navbar navbar-default">
  <h1>My Heading</h1> 
</nav>

When I use the CSS like the below

.navbar{
  min-height: 70px;
  background-color: #e8e8e8;
  text-align: center;
}

it does not align the text inside the navbar to be center instead it aligns to left. I also tried adding CSS for h1. It doesnot work too. What am I missing?.

bhansa
  • 7,282
  • 3
  • 30
  • 55
karthik gorijavolu
  • 860
  • 3
  • 14
  • 28

5 Answers5

0

This is similiar to this question: Bootstrap center heading

bootstrap has added three css classes for text align.

.text-left {
  text-align: left;
}

.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}
Dean
  • 396
  • 3
  • 10
0
.navbar h1 {
  text-align: center;
}

or

.navbar h1 {
  text-align: center !important;
}

If your h1 is styled as a block element, it will definitely be aligned center

Sergey Sklyar
  • 1,902
  • 1
  • 15
  • 27
0

Your example just works fine! However it might be that you need to set the width to the navbar.

.navbar{
  min-height: 70px;
  background-color: #e8e8e8;
  text-align: center;
  width: 100%
}
<nav class="navbar navbar-default">
  <h1>My Heading</h1> 
</nav>
Hielke Walinga
  • 2,677
  • 1
  • 17
  • 30
0

Try this:

nav.navbar.navbar-default h1 {
  text-align: center;
}

or, please add a class to the h1 tag and write css like this:

<nav class="navbar navbar-default">
  <h1 class="heading">My Heading</h1> 
</nav>

nav.navbar.navbar-default h1.heading {
  text-align: center;
}
SUMAN DEBNATH
  • 11
  • 1
  • 2
0

Simply add:

nav > h1
{
   text-align:center !important;
}

Alternatively:

nav > h1
{
    display: inline-block;
    float: none; 
}
Tebogo Khanye
  • 380
  • 1
  • 7
  • 18