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

Adjustable background image with no need for a scroll bar

I am looking to create a static webpage that remains fullscreen without any scrolling. My goal is to have a centered form with the background image adjusting to the window size. As a beginner, I apologize if this request seems too simple. .container { ...

Creating a unique look for SELECT (Option) tags using gradients and a personalized arrow design

Feel free to check out my full HTML code here. You can simply copy and paste it into a demo document on your local machine to see exactly what I'm talking about. My goal is to style the boxes to include both a gradient background AND a unique arrow o ...

How to specify columns when storing data in a CSV file using Scrapy

As I scrape data from the web, I am facing an issue with my csv file where the links column is always displayed as the first column. How can I specify the placement of columns in the csv file? pName = response.css('#search .a-size-medium') ...

Image not found in PDF created from HTML to PDF conversion

I am currently utilizing the HTML-pdf library to convert an HTML page into a PDF format. While the dynamic content is being displayed in the generated PDF, there seems to be an issue with the image not appearing as expected. Despite trying various methods, ...

Identifying CSS when the height of the browser is smaller than the height of the device

On my page, I am facing a situation where the CSS of an element needs to be adjusted for devices like the Nexus 5X. These devices have 'Android nav bars' at the top and bottom, which can push elements around on the page. Currently, I am using jQ ...

Interactive text animation triggered by a click

jQuery ( function ( $ ) { console.log(">>Testing animation"); $('a.loveit').on('click',function(event){ event.preventDefault(); var text = $(this).find('div.love-text'); ...

Having issues with the jQuery .css function?

I need help with hiding and showing tabs on my webpage based on a successful login. I have tried various methods, such as setting the tab to be hidden by default in the HTML code and then using JavaScript to display it upon login. However, none of these me ...

The CSS class names for Next.js have not been defined yet

Just getting started with next js and trying to use css modules for styling my nav component. However, I noticed that the classname I setup for the nav element is not showing up in the rendered DOM. Even though I can see the generated styles by webpack in ...

What is the best way to prioritize List Items over menu items in the front?

Sorry if the title is unclear, let me clarify with some images. First, here is how the navigation bar looks in full window view: Now, this is what happens when I decrease the screen resolution: The items list seems to be hiding behind the menu items. Ho ...

What is the best method to obtain the following id for an image?

Whenever I hover over the li with the number 3, I am getting the wrong number for the next id in the img tag. The first time, I get next id = 4 which is incorrect. But on the second hover, I get next id = 0 which is what I actually need. How can I correctl ...

Excessive space being taken up by the final character in the Material-UI Autocomplete arrow endAdornment

<Autocomplete {...defaultProps} id="disable-close-on-select" disableCloseOnSelect renderInput={(params) => ( <TextField {...params} label="disableCloseOnSelect" variant="standard" /> )} /> Click h ...

Styling the body element in Material UI: A guide to customizing the

I'm having trouble figuring out how to target the root elements using the ThemeProvider in Material UI. const theme = createMuiTheme({ palette: { background: { default: "#00000", backgroundColor : 'black', b ...

Certain CSS styles for components are missing from the current build

After building my Vue/Nuxt app, I noticed that certain component styles are not being applied. In the DEVELOPMENT environment, the styles appear as expected. However, once deployed, they seem to disappear. All other component styles render properly. Dev ...

Provide spacing on the sides for a background position

Is there a way to evenly space my background image with 10px margins on all sides instead of just the left side? Currently, it's only working on the left side. .login-page { display: flex; flex-direction: column; background: url("../src/As ...

Is there a way to ensure the .header and .nav remain fixed at the top of the viewport?

I'm currently working on keeping the .header and .nav elements fixed in the viewport so they don't disappear from view. What's intriguing is that I'm utilizing FlexBox, but I haven't come across a FlexBox feature that allows me to ...

Issues with div misalignment during jQuery animation

I have successfully created an animation where a child div inside a parent div moves up by -60px when the mouse enters the parent div, and returns to its original position when the mouse leaves. However, I am facing an issue where if the mouse moves direct ...

Ways to incorporate bold, unbold, and italic styles into a single heading text within the same line using Bootstrap 4

Is there a way to format a single line of text with certain words bolded and the rest regular? I have a specific example pictured here: Picture of my Issue Specifically, I'm looking to bold "Honors:" and "Capstone:", while keeping the surrounding tex ...

Is there a way to prevent my Header links from wrapping during window size testing?

https://i.stack.imgur.com/YTc3F.png The image above showcases my standard header layout, while the one below illustrates what occurs as I resize the window. https://i.stack.imgur.com/re44T.png Is there a specific CSS solution to prevent the Text navLink ...

Include a basic downward-pointing arrow graphic to enhance the drop-down navigation menus

I am working on a website that has drop-down menu headings styled with CSS. I am looking to enhance these certain menu headers by adding small down-facing arrows indicating they are clickable. Does anyone have any suggestions on how I can achieve this? ...

Connections transition among associated HTML pages

I am working on my very first website using HTML and I'm encountering some challenges with maintaining consistency across pages. On the top of my page, I have a div containing some links. While they function correctly, I noticed that the spacing betw ...