2

I'm looking for handle my Bootstrap navbar title and I don't overcome to center my tag.

My script for this part looks like :

<style>
  .navbar.navbar-inverse .navbar-header .navbar-brand {
    display: inline-block;
    text-align:center;
    float: none;
    vertical-align: top;
  }
</style>

<!-- #################### -->
<!-- Upper navigation bar -->
<!-- #################### -->

<nav class="navbar navbar-inverse">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <div class="navbar-header">
                    <a class="navbar-brand"> Choix du logiciel </a>
                </div>
            </div>
        </div>
    </div>
</nav>

I would like to center : Choix du logiciel

enter image description here

I already read this post : Center content in responsive bootstrap navbar

But I don't find a way to make what I want :/

I think that it's not hard, but up to now it's not a success.

Thank you

Community
  • 1
  • 1
Essex
  • 6,042
  • 11
  • 67
  • 139
  • So you're saying that adding `text-align:center;` to your navbar doesn't working right? – Chirag Apr 19 '17 at 13:47
  • Yes, I forgot this line when I wrote my question. I would like to center this sentence but none effect up to now. – Essex Apr 19 '17 at 13:48

8 Answers8

4

EDIT : It should work with this fiddle

.navbar.navbar-inverse .navbar-header .navbar-brand {
        display: block;
        text-align:center;
        float: none;
        vertical-align: top;
}

.navbar.navbar-inverse .navbar-header{
  float: none; 
}
Vincent G
  • 8,547
  • 1
  • 18
  • 36
1

take text-align: center; out from your css .navbar.navbar-inverse.navbar-header.navbar-brand {..} and move it to

.navbar-header {
  text-align: center;
}

will fix it.

.navbar.navbar-inverse.navbar-header.navbar-brand {
  display: inline-block;
  float: none;
  vertical-align: top;
}

.navbar-header {
  text-align: center;
}

.bg-red {
  background-color: red;
}

.bg-yellow {
  background-color: yellow;
}
<!-- #################### -->
<!-- Upper navigation bar -->
<!-- #################### -->
<div class="wraper">
  <nav class="navbar navbar-inverse">
    <div class="container-fluid">
      <div class="row">
        <div class="col-md-12">
          <div class="navbar-header bg-yellow">
            <a class="navbar-brand bg-red"> Choix du logiciel </a>
          </div>
        </div>
      </div>
    </div>
  </nav>
</div>
Dalin Huang
  • 11,212
  • 5
  • 32
  • 49
1

Use this css:

.navbar.navbar-inverse .navbar-header {
    text-align: center;
    width: 100%;
}

.navbar.navbar-inverse .navbar-header .navbar-brand {
    display: inline-block;
    float: none;
}
Douwe de Haan
  • 6,247
  • 1
  • 30
  • 45
1

Change inline block to just block.

.navbar.navbar-inverse .navbar-header .navbar-brand {
    display: block;
    text-align: center;
    float: none;
    vertical-align: top;
  }
Lakindu Gunasekara
  • 4,221
  • 4
  • 27
  • 41
0

Just put text-align:center on .navbar-header. It must work.

Your a tag must be display block so your text inside tag can be centered.

You can put display:block on a tag too.

0

Adding display:inline-block to .navbar-brand may fix it. And also text-align:center to .navbar-header

Orkun Tuzel
  • 1,342
  • 10
  • 22
0

Check this and see please

.navbar.navbar-inverse .navbar-header .navbar-brand {
        display: block;
        text-align: center;
        float: none;
        vertical-align: top;
      }
0

This is now possible with inbuilt bootstrap class '.justify-content-center', but will be applicable on bootstrap versions v4.4 and above

Can be applied to a nav component like below

 <nav className="navbar navbar-light bg-light justify-content-center">
    <span className="navbar-brand mb-0 h1">Navbar</span>
 </nav>
MDT
  • 1,535
  • 3
  • 16
  • 29