skip to Main Content

my text can’t be align center in the collapsable toggle. I think it’s because the text-align is align to the attritube… I tried many method, but still can;t seems to get it. Mind lend a help? Thanks!!

Using Twitter-Bootstrap 4.5.1

enter image description here

Code snippet:

html

<div class="container">
            <div class="nav-header">
                <div class="navbar-brand">
                    <a href="index.html">
                        <h1>Food LLC.</h1></a><hr>
                </div>

                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#collapsable-nav" aria-expanded="false" aria-controls="navbar">
                <span class="material-icons">menu</span> 
                </button> 
                

             <div id="collapsable-nav" class="collapse navbar-collapse">
             <ul id="nav-list" class="nav navbar-nav navbar-right">
                <li class="visible-xs active">
                    <a href="index.html">
                        Home
                    </a>
        </li>
        <li>
          <a href="chicken.html">Chicken</a>
        </li>
        <li>
          <a href="#">Beef</a>
        </li>
        <li>
          <a href="#">Sushi</a>
        </li>
        
      </ul><!-- #nav-list -->
    </div>
        </div>

CSS

    button.navbar-toggle{
  position: absolute;
  right: 50px;
  top: 10px;
}
.navbar-nav {
    float:none;
    margin:0 auto;
    display: block;
    text-align: center;
}

#nav-list{
  margin-top: 10px;
  margin-bottom: 10px;
  float: right;
  
}
#nav-list a {
  color: white;
  font-size: 1.3em;
  font-style: italic;
}
#nav-list li {
  margin-bottom: 5px;
}
#nav-list a:hover {
  text-decoration: none;
  color: #D3D3D3;
}

2

Answers


  1. Try it without Float:

    .navbar-nav {
        margin:0 auto;
        display: block;
        text-align: center;
    }
    
    
    Login or Signup to reply.
  2. If you think how to align .li elements I will suggest you to do this – I am also using it.
    e.g:

    <center>
    <li>Hello</li>
    </center>
    

    ……… And do this for every li element. Hope this will help you!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search