Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Centre Nav Bar

Hi! I am embarking on my first project as a freelancer and I am creating a store on wordpress and woocomerce. I am using a starter theme called _tk

I just can't seem to be able to centre the nav bar in the middle. Any help would be appreciated. Thanks

The website is http://exhibit.brightideadesign.net/

<div class="container">
    <div class="row">
        <div class="col-sm-12 col-md-12 text-center" id="logo"> <!-- logo-->
            <a id="brand" href="/">EXHIBIT<img id="logo" src=""></a>
        </div>
    </div>
</div>


<nav class="site-navigation">
<?php // substitute the class "container-fluid" below if you want a wider content area ?>
    <div class="container">
        <div class="row">
            <div class="site-navigation-inner col-sm-12">
                <div class="navbar navbar-default">
                    <div class="navbar-header">
                        <!-- .navbar-toggle is used as the toggle for collapsed navbar content -->
                        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse">
                            <span class="sr-only"><?php _e('Toggle navigation','_tk') ?> </span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>

                        <!-- Your site title as branding in the menu -->
                        <!--<a class="navbar-brand" href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>-->
                    </div>

                    <!-- The WordPress Menu goes here -->
                    <?php wp_nav_menu(
                        array(
                            'theme_location'    => 'primary',
                            'depth'             => 2,
                            'container'         => 'div',
                            'container_id'      => 'navbar-collapse',
                            'container_class'   => 'collapse navbar-collapse',
                            'menu_class'        => 'nav navbar-nav',
                            'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
                            'menu_id'           => 'main-menu',
                            'walker'            => new wp_bootstrap_navwalker()
                        )
                    ); ?>

                </div><!-- .navbar -->
            </div>
        </div>
    </div><!-- .container -->
</nav><!-- .site-navigation -->

this is the css I tried

@media (min-width: 768px) {
     .navbar .navbar-nav {
         display: inline-block;
         float: none;
         vertical-align: top;
     }

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

1 Answer

Hi David,

On the ul id main-menu remove the float left and add display block and margin: 0 auto. Then on the li's remove the float left and make them inline-block.

#main-menu {
  float: none;
  display: block;
  margin: 0 auto;
}


#main-menu > li {
  float: none;
  display: inline-block;


}

is this the idea Mark? Can't seem to work it out. Thanks for the help

Sorry about that David. Text align center on the #main-menu and it needs to be block. It is currently set as inline-block. Margin: 0 auto isn't really required but would center the UL if something else forced a width change. You can remove that if there are no chances it will change.

Thank so much mark! Appreciate it!