Menu Items at the Center

I am currently working on a Wordpress website and struggling to center the menu items that are currently aligned to the left. I have created a child theme from the existing theme's code, but still can't figure out how to achieve this simple task. Any assistance or guidance would be greatly appreciated! Thank you.

This is the code snippet from header.php:

<!-- Header -->
    <header id="header" class="cf">
        <div class="in">
            <section class="logo-box <?php echo ( is_active_sidebar( 'header-call-to-action-sidebar' ) ) ? 'logo-box-header-cta': 'logo-box-no-header-cta'; ?> <?php echo ( ! is_active_sidebar( 'header-call-to-action-sidebar' ) && ! has_nav_menu( 'top_nav' ) ) ? 'logo-box-full-width': false; ?>">
                <?php sds_logo(); ?>
                <?php sds_tagline(); ?>
            </section>

            <aside class="header-widget-container <?php echo ( ! is_active_sidebar( 'header-call-to-action-sidebar' ) && ! has_nav_menu( 'top_nav' ) ) ? 'header-widget-container-no-margin': false; ?>">
                <?php if( has_nav_menu( 'top_nav' ) ) : // Top Navigation Area ?>
                    <nav class="top-nav">
                        <?php
                            wp_nav_menu( array(
                                'theme_location' => 'top_nav',
                                'container' => false,
                                'menu_class' => 'top-nav secondary-nav menu',
                                'menu_id' => 'top-nav'
                            ) );
                        ?>
                    </nav>
                    <section class="clear"></section>
                <?php endif; ?>

                <?php if ( is_active_sidebar( 'header-call-to-action-sidebar' ) ) : ?>
                    <section class="header-cta-container header-call-to-action">
                        <?php sds_header_call_to_action_sidebar(); // Header CTA Sidebar ?>
                    </section>
                <?php endif; ?>
            </aside>
        </div>

        <!-- main nav   -->
        <nav class="primary-nav-container">
            <div class="in">
                <?php


                    wp_nav_menu( array(
                        'theme_location' => 'primary_nav',
                        'container' => false,
                        'menu_class' => 'primary-nav menu',
                        'menu_id' => 'primary-nav',
                        'fallback_cb' => 'sds_primary_menu_fallback'
                    ) );
                ?>
            </div>

            <button class="mobile-nav-button">
                <img src="<?php echo get_template_directory_uri(); ?>/images/menu-icon-large.png" alt="<?php esc_attr_e( 'Toggle Navigation', 'socialize' ); ?>" />
                <img class="close-icon" src="<?php echo get_template_directory_uri(); ?>/images/close-icon-large.png" alt="<?php esc_attr_e( 'Close Navigation', 'socialize' ); ?>" />
                <?php _e( 'Navigation', 'socialize' ); ?>
            </button>
            <?php soc_mobile_menu(); ?>
        </nav>
    </header>

And this CSS section is taken from style.css:

nav.primary-nav-container {
    position: relative;
    z-index: 5;
    background: #ffffff;
    width: 100%;
    float: left;
    margin-top: 20px;
    border-top: 1px solid #8d7249;
    text-align:center;
}

/* Additional CSS styles below */
...

Answer №1

If you want to achieve a similar effect, consider this:

nav.main-navigation-container {
    position: relative;
    z-index: 5;
    background: #ffffff;
    width: 100%;
    float: left;
    margin-top: 20px;
    border-top: 1px solid #8d7249;
    /*text-align:center;*/
}

nav .main-navigation{
    width: 100%;
    display: inline-block;
    clear: both;
    position: relative;
    float: left;
    margin: 0 auto;
    text-align:center;
}

nav .main-navigation item{
    /*float: left;*/
    display:inline-block;
    position: relative;
    -webkit-transition: all .3s ease-in-out;
    -moz-transition: all .3s ease-in-out;
    -ms-transition: all .3s ease-in-out;
    -o-transition: all .3s ease-in-out;
    transition: all .3s ease-in-out;
    border-right: 1px solid #8D7249;
}

nav .main-navigation item link{
    /*float: left;*/
    text-decoration: none;
    color: #8D7249;
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    padding: 15px 25px;
    -webkit-transition: all .3s ease-in-out;
    -moz-transition: all .3s ease-in-out;
    -ms-transition: all .3s ease-in-out;
    -o-transition: all .3s ease-in-out;
    transition: all .3s ease-in-out;
    border-right: 0.5px solid #8D7249;
    border-bottom: 0.5px solid #8D7249;
    border-top: 0.5px solid #8D7249;
}

I trust this will be useful for your needs.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the reason for padding influencing the overall dimensions?

The result I achieved was unexpected. After realizing that the text was positioned above the green markers, I decided to add some internal padding to the three pink containers. To my surprise and disappointment, when I made this adjustment, it ended up lo ...

Tips for positioning text on the left and right sides of a div in HTML styling

I am struggling with positioning two pieces of text within a div. Despite having some styling already in place, the text is currently displaying one after the other on the left-hand side. I want to position one piece of text to the left and another to the ...

Adjusting the visibility of a div as you scroll

I'm trying to achieve a fade-in and fade-out effect on div elements when scrolling over them by adjusting their opacity. However, I'm facing difficulties in getting it to work properly. The issue lies in the fact that my div elements are positio ...

Ways to navigate through a webpage without encountering any overflow issues

My window is too small to scroll, but I still need the ability to do so. Is it possible to scroll even when the height of the container is not large enough to display the scrollbar? Below is the code I am using to achieve scrolling: setTimeout(function() ...

Integrating dynamic PHP echo strings from a database into an established CSS layout

I am currently exploring PHP and MySQL databases, and I have managed to develop a basic search engine for my website. However, I am facing an issue that I am struggling to resolve: Is there a way to integrate the PHP echo output (search results) into the ...

The admin-ajax.php file in Wordpress is sending back php code instead of the expected json format

How do I configure WordPress to return JSON on Nginx? When making Ajax calls in my WordPress site, instead of receiving plain JSON, I see <?php JSON. Everything works fine on the site, except for admin-ajax calls. Example of a regular call: https://i. ...

Tips for utilizing div as a dropdown menu

I have a challenge with the following code and I am looking to make it function like a dropdown one by one For example: ABCD ABCD 1234 ABCD 1234 abcd <ul class="first"> <li class="first-a"><a href="https://someurl">ABCD&l ...

Maintaining an even distribution of flex children on each line as they wrap to the next line

I am curious about finding a way to maintain an even distribution of elements on each line, including the last one, using flex-wrap or any other flexbox technique. For example, let's say I have a flexbox with 6 elements. When it wraps, I would like t ...

Manipulating certain attributes of a CSS class for a specific division element

I'm working with a div that has a CSS class applied to it. The class declares the height as x pixels, but I actually want my div to be y pixels high. Is there a way to override the height parameter of the CSS without making changes to the CSS file? ...

What is the proper method for storing user registration information in the database so that it can be easily retrieved and accessed later? (Error message)

User.cs: An error is occurring in the User class where 'User' is not a valid type in the context of TestBlazor project. It happened when attempting to save user registration data. using System; using System.Collections.Generic; using S ...

Anchoring links on a webpage that provide users with a clear indication of their current position within the page

In the scenario of a single-page website with various sections (divs) and a header containing links to different anchors on the page, there is a desire to have an indicator highlight which anchor the user is currently viewing. An example of this can be s ...

What is the best way to keep the heights of two divs in sync?

Is there a way to make two divs have the same height, even though their content determines their individual heights? I am looking for a solution that doesn't involve using a table or a parent div. I'm new to JavaScript, so I'm hoping there i ...

Files are nowhere to be found when setting up an angular project

After creating an Angular project, I noticed that some key files were missing in the initial setup, such as app.modules.ts and app-routing.modules.ts The project was generated using the command ng new name Here is a screenshot displaying all the files th ...

How to make the Bootstrap mobile navigation menu taller?

I'm having trouble adjusting the height of the collapsed mobile drop-down navigation. Right now, it's stuck at around 340px and I need it to expand to accommodate all the menu items within the collapsed nav. Despite my efforts searching on Google ...

Tips for incorporating unique images into each individual flex box

I am new to the world of coding, having just embarked on this journey less than a week ago. Following a tutorial by a developer on YouTube, I tried to add my own twist to the project in order to differentiate it from the original. However, I've hit a ...

Issues with CSS rendering have been encountered on the Facebook page

I'm experiencing an issue with the rollover CSS on Facebook's rendering engine. I'm not sure if I made a mistake in my code or if there are limitations with certain CSS properties on custom Facebook pages. Here is the code I am using: <l ...

Nested CSS selector within a parent element

How can I change the color of both elements inside a custom button when the button is active? The first color is defined by the class of the button, and the second color is defined by the class of the span inside that button. CSS: .buttonClass{ color:b ...

Having trouble with Firefox not recognizing the linear gradient color in my CSS3 code

I'm working on implementing a linear gradient background using CSS, but I'm facing an issue with Firefox not displaying it correctly. body { height: 100%; /*background-color: #F0F0F0;*/ background-repeat: repeat-x; /* Safari 4-5, Chrome 1-9 */ ...

Tips for ensuring that CSS hover effects stay in place even when the page is scrolled

i'm having trouble with a project in React JS that I received from another team. I'm not very confident in my skills with React JS, and I'm facing an issue where a certain part of the page is supposed to change to red when hovered over. Howe ...

Utilizing Ajax to Dynamically Update Link Styles

When using an AJAX request to load a portion of a webpage, the content is delivered by a framework and then inserted into the DOM tree using jQuery. Everything seems to be working well so far. However, I encountered an issue when trying to use background ...