Search code examples
cssrflexdashboard

Align elements on center of the navigation bar, except one (or more) elements


I have this application, written in RMarkdown:

I tried to center the .navbar elements, except for an icon on the right. This code works well:

.navbar-nav {
  position: absolute;
  left: 50%;
  transform: translatex(-50%);
}

But the icon is in the center:

enter image description here

I wanted only this icon to be at the "initial position". I tried to force this permanence with this code:

.fa-question-circle {
  float: right !important;
}

But nothing happened.

Edit

When resize screen, the icon .fa-question-circle gets out of hamburguer menu when I click on it:

enter image description here

Hamburger menu code:

@media (max-width: 950px) {
  .navbar-header {
    float: none;
  }
  .navbar-left,.navbar-right {
    float: none !important;
  }
  .navbar-toggle {
    display: block;
  }
  .navbar-collapse {
    border-top: 1px solid transparent;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
  }
  .navbar-fixed-top {
    top: 0;
    border-width: 0 0 1px;
  }
  .navbar-collapse.collapse {
    display: none!important;
  }
  .navbar-nav {
    display: block !important;
    float: none!important;
    margin-top: 7.5px;
  }
  .navbar-nav>li {
    float: none;
  }
  .navbar-nav>li>a {
    padding-top: 10px;
    padding-bottom: 10px;
  }
  .collapse.in{
    display: block !important;
  }
}

I'm almost certain that the adjustment needs to be made here:

.navbar-left,.navbar-right {
  float: none !important;
}

I tried this, but it didn't work:

.navbar-left,.navbar-right {
  float: none !important; 
  display: block !important; 
  position: absolute !important;
}

Objective: The "icon" should be the last option on the hamburger menu. Like this:

enter image description here


Solution

  • From the link you posted, you need to add this in your CSS

    .navbar-right {
        left: auto;
        right: 10px;
        transform: none;
    }
    

    On your second problem

    Add this CSS to your ul

    ul {
        display: flex;
        white-space: nowrap;
    }