How to centrally position a menu item using Bootstrap

I'm having difficulty centering the logo and menu in the md and sm view.

I would like to animate the margin of the brand logo and menu items, but using margin auto and position absolute is not working for me.

Using TransformX and col-offset helps with centering, but it's not pixel-perfect. Also, when animating the margin, the logo and menu lose their center alignment.

<nav class="navbar navbar-default navbar-fixed-top container menufix">


                <div class="row row-eq-height" id="rowmenu">
                    <div class="row row-eq-height-resp">
    <!-- Brand Logo --> 
                        <div class="col-xs-10 col-sm-12 col-md-12 col-lg-12">
                            <a class="navbar-brand" id="brand-logo" href="#">
                                <img alt="BrandLogo" class="brandlogo" src="/wp-content/themes/kdproduction/logo.png">
                            </a>
                        </div>
    <!-- Brand and toggle - mobile display -->
                        <div class="col-xs-2 hidden-lg hidden-md hidden-sm">
                            <button type="button" class="btn-resp-style" data-toggle="collapse" data-target=".navbar-collapse">SVG</button>
                        </div>
                    </div>

<!-- Main Top nav -->
                    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-8" >
                        <div class="navbar-collapse collapse">
                                <?php wp_nav_menu( array( 
                                    'theme_location' => 'primary',
                                    'container' => false,
                                    'menu_id' => 'kdnavmenulista',
                                    'menu_class' => 'nav navbar-nav navbar-header kdnavmenulista'
                                        )); 
                                ?>
                        </div><!-- /.navbar-collapse -->
                    </div>
                </div>
        </nav><!-- /.container -->

Answer №1

If you're tired of seeing this:

<a class="navbar-brand" id="brand-logo" href="#">
    <img alt="BrandLogo" class="brandlogo" src="/wp-content/themes/kdproduction/logo.png">
</a>

give this a try instead:

<div style="width:100%; display:flex; justify-content:center; align-items:center;">
    <a class="navbar-brand" id="brand-logo" href="#">
        <img alt="BrandLogo" class="brandlogo" src="/wp-content/themes/kdproduction/logo.png">
    </a>
</div>

Feel free to let me know how it worked out.

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

The onsubmit() form isn't working as intended

I have developed a JavaScript function to control the required input texts in my form. However, I am facing an issue where the error message does not appear when clicking the button without filling out the required field, and it allows me to navigate to an ...

Printing the footer on a page in ASP.NET is essential for providing additional information

I need to print an HTML page with specific content. The content includes a div with some text to be printed. Additionally, I have a footer with a class of divFooter that contains more content. <div>content to print</div> The CSS for styling t ...

Sliding and repositioning elements using jQuery

My goal is to build a simple slideshow for learning purposes. I want the list items to slide automatically to the left in a continuous loop. I've written some code that makes the slides move, but I'm struggling to set the correct position for ea ...

A fresh javascript HTML element does not adhere to the css guidelines

While attempting to dynamically add rows to a table using Javascript and jQuery, I encountered an issue. Here is my code: <script> $(document).ready(function(){ for (i=0; i<myvar.length; i++){ $("#items").after('<tr class="item- ...

onpageshow event behaves as expected exclusively on webkit browsers (triggers function solely when visible on the screen)

I am inserting an HTML file using an object tag. The encompassing div of the object tag is hidden with a display:none property. However, I encounter an issue where the onpageshow event that I placed on the body tag of the HTML object behaves differently a ...

Guide to switch background image using querySelector

I am currently trying to figure out how to set the background image of a div block by using querySelector. I have attempted various methods in my test code below, but unfortunately none seem to be working. Can someone please provide assistance? <!DOC ...

HTML: Align DIV contents next to each other without any overlap

Below are three boxes displayed. Boxes 1 and 3 appear fine, but in box 2 the text content is overlapping. The issue lies with the <div> having the class .vertical_center.grade_info which has a specific margin-left of 100px, causing the overlap. I ne ...

Display content exclusively within a modal specifically designed for mobile devices

I want to implement a feature where a button triggers a modal displaying content, but only on mobile devices. On desktop, the same content should be displayed in a div without the need for a button or modal. For instance: <div class="container&quo ...

Link with javascript onClick attribute

Is there a way to combine a JavaScript "onClick" event with an HTML "a href" link? I would like for the first step to be triggered upon clicking the link using "onClick", and if that is successful, the user should then be redirected to another page using t ...

What is the best way to adjust word spacing in Bootstrap?

https://i.sstatic.net/E7diW.jpg The problem persists even after trying to create a class and assign it to the ul tag. .spacing { word-spacing: 100px; } <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protecti ...

Transitioning to mui5's sx prop instead of makeStyles is generating a typescript error - none of the overloads match this call when passing an object with

I encountered an issue while converting a component to mui 5. Here is the original code snippet: const useStyles = makeStyles({ imageContainer: { display: "flex", width: "65%", float: "left", marginRight ...

Develop an interactive AngularJS application with a dynamic Bootstrap table feature

I'm in the process of transitioning my existing jQuery code to AngularJS. One part of the code involves creating a dynamic Bootstrap table based on JSON data retrieved from a Spring REST service. The snippet below shows the jQuery code used to create ...

Customizing existing Mui classes through the use of makeStyles

Recently, I made a small change in my approach to styling by moving CSS directly into my component files using styled components, emotion, and make styles. This decision was driven by the benefits of easier management and improved development experience. A ...

Issue with radio button click event not triggering

Whenever I click on a radio button, I want to call a function, but for some reason, it's not working as expected. I found this fiddle that demonstrates exactly what I want, but when I implement it in my code, it doesn't work. Here's a snipp ...

I'm looking to increase a specific value by a set amount each time there is an input event triggered

I have created a range slider, but I am facing an issue with the oninput event. I want to increment a specific amount whenever the slider is adjusted. For example, I want to increase the amount by $150 when the slider is at $2000, and by $45000 for a parti ...

The Bootstrap 4 Modal has a one-time activation limit

It seems that I mistakenly created two modals. The issue arises when I open either of them for the first time and then close it, as from that point on, neither modal is able to be opened again by performing the same action that initially worked. https://i ...

What is the best way to conceal a row when a particular field is devoid of content?

Is it possible to hide an entire table row if a field is empty? For example: https://i.sstatic.net/tMW7L.png If a certain field is empty, I want the entire row to be hidden, either using JavaScript or jQuery. I have tried some methods but none of them fu ...

Transforming the mui stepper connection into a progress bar is simple. Each step contains individualized content to guide you through the process

Is there a way to make the MUI stepper connector act as a progress indicator? I have step content and connectors as separate divs, but I'm having trouble styling them. Any assistance would be greatly appreciated! ...

If the window width is less than the specified value, hide the DIV and replace it with a

I came across a discussion about hiding a div if the screen is narrower than 1024px, and I'm looking to implement something similar based on the quoted code below. Essentially, I want to hide one div (id="krug_wide") if the window width is less than 1 ...

Looking to dynamically set a background image using data fetched from an API in a ReactJS project

Looking to incorporate a background image from an API response in ReactJS Here is some sample code: useEffect(() => { axios.get(`https://apiaddress=${API_KEY}`) .then(res=>{ console.log(res); setRetrieved(res.data); console.log(retrieved ...