Aligns navbar bootstrap text vertically

Asked

Viewed 2,208 times

5

I’m using in my project two navbar and I’m having a problem aligning the text of the first menu vertically, I tried to create a structure to change but did not succeed, what I have is this:

First Navbar:

    <div class="navbar-collapse collapse" id="MenuUm">
      <div class="search-side"> <a href="#" class="show-search"><i class="icon-search-1"></i></a>
        <div class="search-form">
          <form autocomplete="off" role="search" method="POST" class="searchform" action="resultado.php">
            <input type="text" value="" name="s" id="s" placeholder="Buscar...">
          </form>
        </div>
      </div>
      <!-- Início da Lista de Navegação-->
      <ul class="nav navbar-nav navbar-right">
        <li> <a href="catalogos.php">catálogos e manuais</a> </li>
        <li> <a href="cores.php">cores e linha</a> </li>
        <li> <a href="garantia.php">garantia e uso</a> </li>
      </ul>
    </div>

Second Navbar:

    <div class="navbar-collapse collapse" id="MenuDois"> 
      <!-- Início da Lista de Navegação-->
      <ul class="nav navbar-nav navbar-right">
        <li> <a href="index.php">INÍCIO</a> </li>
        <li> <a href="empresa.php">EMPRESA</a> </li>
        <li> <a href="produtos.php">PRODUTOS</a> </li>
        <li> <a href="representantes.php">REPRESENTANTES</a> </li>
        <li> <a href="encontrar.php">ONDE ENCONTRAR</a> </li>
        <li><a href="contato.php">CONTATO</a></li>
      </ul>
    </div>

The css of Navbar is like this:

.navbar-nav {
  margin: 7.5px -15px;
}

.navbar-nav > li > a {
  padding-top: 10px;
  padding-bottom: 10px;
  line-height: 20px;
}

What I tried to do was create two different structures for each Navbar, But like I said, it didn’t work out.

.navbar-nav-1 > li > a {
  padding-top: 10px;
  padding-bottom: 10px;
  line-height: 20px;
}

.navbar-nav-2 > li > a {
  padding-top: 10px;
  padding-bottom: 10px;
  line-height: 20px;
}

To make it easier to understand I’ll attach an image of what I’m trying to do, see: Example of what I need

The site under development is this: Website

3 answers

3


With the use of Grid bootstrap to make this menu without additional css.

Step by step:

1º - I added a container to center

2° - I added 1 row divided in 4|8, the 4 will have the logo of 8 the menus.

3° - I added the logo normally inside the col-md-4.

4º - I added each menu in a Row inside the col-md-8 , each menu received the pull-right, to be right aligned.

Example:

  <div class="container">
     <div class="row">
        <div class="col-md-4">
           <img src="http://ancestofados.com.br/anc/images/anc.fw.png" alt="logo">
        </div>
        <div class="col-md-8">

           <!--  MENU AQUI 1-->
           <div class="row">
              <div class="col-md-11 pull-right">
                 <ul class="nav nav-pills">
                    <li role="presentation"><a href="#">Catálogos e manuais</a></li>
                    <li role="presentation"><a href="#">Cores e linha </a></li>
                    <li role="presentation"><a href="#">Garantia e uso </a></li>
                    <li role="presentation">
                       <form class="navbar-form" role="search">
                          <div class="input-group">
                             <input type="text" class="form-control" placeholder="Pesquisar..." name="srch-term" id="srch-term">
                             <div class="input-group-btn">
                                <button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
                             </div>
                          </div>
                       </form>
                    </li>
                 </ul>
              </div>
           </div>

           <!--  MENU AQUI 2 -->
           <div class="row">
              <div class="col-md-12 pull-right">
                 <ul class="nav nav-pills">
                    <li role="presentation"><a href="#">INÍCIO </a></li>
                    <li role="presentation"><a href="#">EMPRESA </a></li>
                    <li role="presentation"><a href="#">PRODUTOS </a></li>
                    <li role="presentation"><a href="#">REPRESENTANTES </a></li>
                    <li role="presentation"><a href="#">ONDE ENCONTRAR </a></li>
                    <li role="presentation"><a href="#">CONTATO</a></li>
                 </ul>
              </div>
           </div>

        </div>
     </div>
  </div>

As it turned out:

inserir a descrição da imagem aqui

See on the jsfiddle

  • Hello @Gabrielrodrigues, thanks for the help, but I have a problem when the page is resized, navbar-toggle are not being displayed, so what I saw in their example they were deleted.

  • @adventistapr happens that this navigation is done by the simple Nav and not navbar, it will get well formatted from 1230 600 resolution up, if you want a responsive menu then you can add a media to show the responsive menu in a lower resolution.

2

For the site you went through, I think it would be interesting to review the structure of your header because the bootstrap framework was not made to keep 2 navbar inside each other. From what I saw on the link you went through, what you could do is add this:

using the flex property (future of CSS rs)

.navbar-top > .menu1 >ul.navbar-right { 
    height: 101px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
}

using the old form (like table)

.navbar-top > .menu1 >ul.navbar-right { 
    height: 101px;
    display: table;
}

.navbar-top > .menu1 >ul.navbar-right li a {
    height: 101px;
    display: table-cell;
    vertical-align: middle;
}

Also, in terms of design you putting that hidden search there will mess you up as to the sizes of media queries. the best to do would be for you to insert it inside the navbar as a li and open, thus not taking up memory for the animations, its design is already handled when the bootstrap adapt and get the smaller menu.

2

In style.css, in class search-side add the property margin-top with 15px

.search-side {
    margin-top: -15px !important;
}

At first navbar define a class name as navbar-primeira and add property

.navbar-primeira { 
   margin-top: 35px !important; 
}

And for the second navbar add the properties

ul li a { 
    max-height: 55px !important; 
    margin-top: -15px !important;
}

And finally, in the div with class hidden-header, remove the attribute style="height: 161px;" which was set directly on html.

I left Outline on, but that’s it. inserir a descrição da imagem aqui

  • Hello @Douglasgaldino, thanks for the reply, I’m trying to change according to what you indicated but I’m not getting the result you had, what is in the image of your reply.

  • I used your website to make the changes, directly on Chrome. You changed something after 04/01?

  • Had sent an update without Outline and without the style="height: 161px;", his reply was the one that came closest to the solution I need.

  • I changed the post values, try to replicate again.

  • I just changed the information, but the first navbar is getting a grey background and the search field misaligned, please go to: http://ancestofados.com.br/anc/index.php

  • Put the input next to the icon, the rest is to change the values passed to match the correct position.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.