Center logo on mobile in WordPress

Tom Beckerle

mobileI've looked everywhere for centering a logo on mobile in WordPress, and I can't find anything. Here's what I've styled...

I also want the phone number to move into the navbar on mobile, but one step at a time, right? Any help is greatly appreciated...

Updated with more code. My apologies. I'm not sure if my media query is evey applying. I tested on Firefox and it only shows two of the four styles I've used. Is that normal? The float right and font-size aren't being displayed.

I hope if I can nail this down the other site section will be easier. I do everything in WordPress and I like the functionality. I also want to understand the CSS before I try tackling PHP, if that makes sense.

@media screen and (max-width: 480px) {
    a[href^="tel:"] {
      color: black;
      text-decoration: none;
      float: none;
    }
    .navbar-brand {
      margin: 0 !important;
    }

}

// ------------- Telephone Styling ------------ //

#telephone {
    text-align: center;
    margin-top: 15px;
    font-size: large;
    float: right;
}

a[href^="tel:"] {
  color: black;
  text-decoration: none;
  display: inline;
}


<div class="hfeed site" id="page">

<!-- ******* Header ******* -->
<header>
    <div class="wrapper-fluid">

<!-- Your site title as branding in the menu -->
    <div class="container">
        <div class="row">
            <div class="col-md-6">
                <?php if ( ! has_custom_logo() ) { ?>

                    <?php if ( is_front_page() && is_home() ) : ?>

                        <h1 class="navbar-brand mb-0"><a rel="home" href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>

                    <?php else : ?>

                        <a class="navbar-brand" rel="home" href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"><?php bloginfo( 'name' ); ?></a>

                    <?php endif; ?>


                <?php } else {
                    the_custom_logo();
                } ?>
            </div>
<!-- end custom logo -->
            <div class="col-md-6">
                <div id="telephone">
                <p>Call Now<br>
                    <i class="fa fa-phone"></i>
                <a href="tel:636-244-9045">636-244-9045</a></p>
            </div>
        </div>
    </div>
</div>
<!-- ******************* The Navbar Area ******************* -->
<div class="wrapper-fluid wrapper-navbar" id="wrapper-navbar">

    <a class="skip-link screen-reader-text sr-only" href="#content"><?php esc_html_e( 'Skip to content',
    'understrap' ); ?></a>

    <nav class="navbar navbar-expand-md navbar-dark bg-dark">

    <?php if ( 'container' == $container ) : ?>
        <div class="container">
    <?php endif; ?>

            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>

            <!-- The WordPress Menu goes here -->
            <?php wp_nav_menu(
                array(
                    'theme_location'  => 'primary',
                    'container_class' => 'collapse navbar-collapse',
                    'container_id'    => 'navbarNavDropdown',
                    'menu_class'      => 'navbar-nav',
                    'fallback_cb'     => '',
                    'menu_id'         => 'main-menu',
                    'walker'          => new WP_Bootstrap_Navwalker(),
                )
            ); ?>
        <?php if ( 'container' == $container ) : ?>
        </div><!-- .container -->
        <?php endif; ?>

    </nav><!-- .site-navigation -->

   </div><!-- .wrapper-navbar end -->
</div>
    </div>
</header>
clauub

I checked your website and I got your problem.

You have for .navbar-brand this code :

display: inline-block;
padding-top: .3125rem;
padding-bottom: .3125rem;
margin-right: 1rem;
font-size: 1.25rem;
line-height: inherit;
white-space: nowrap;

And problem is with display: inline-block; and margin-right: 1rem; these two are stopping your action to center logo.

So replace .navbar-brand like this :

padding-top: .3125rem;
padding-bottom: .3125rem;
font-size: 1.25rem;
line-height: inherit;
white-space: nowrap;

And code to center the logo inside .img-fluid :

display: block;
margin: 0 auto;

This works for sure. Hope you understand.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related