html - How do I center elements in a div or nav element? -
this navigation bar:
#main-nav-bar .nav-item { display: inline-block; padding: 0.5%; border-right: 1px solid white; } #main-nav-bar { text-decoration: none; color: #cfcfe0; }
<nav id="main-nav-bar"> <a href="#services" class="nav-tab nav-item selected">services</a> <a href="#resources" class="nav-tab nav-item">resources</a> <a href="#contact-us" class="nav-tab nav-item">contact us</a> <a href="#company" class="nav-tab nav-item">company</a> <form class="searchbar nav-item" action="http://www.google.com/search" name="f" target="_blank"> <input size="10" name="q" value="" class="searchform"> <input type="submit" value="go!" name="btng" class="searchbutton"> <br> </form> </nav>
i want center 5 items inside nav
element in responsive way. tried set margin
s, still not perfect centering.
how center them ?
use display:flex
, justify-content:center
in #main-nav-bar
#main-nav-bar { display: flex; justify-content: center; border:1px dashed red; background:green } #main-nav-bar .nav-item { display: inline-block; padding: 0.5%; border-right: 1px solid white; } #main-nav-bar { text-decoration: none; color: #cfcfe0; }
<nav id="main-nav-bar"> <a href="#services" class="nav-tab nav-item selected">services</a> <a href="#resources" class="nav-tab nav-item">resources</a> <a href="#contact-us" class="nav-tab nav-item">contact us</a> <a href="#company" class="nav-tab nav-item">company</a> <form class="searchbar nav-item" action="http://www.google.com/search" name="f" target="_blank"> <input size="10" name="q" value="" class="searchform"> <input type="submit" value="go!" name="btng" class="searchbutton"> <br> </form> </nav>
Comments
Post a Comment