Unable to center div in WordPress theme

Having a div with the usual margin: 0 auto and text align: center, I noticed that the first letter of the text/image is centered within the div, not the image itself. Additionally, there seems to be a slight misalignment in the rest of the content by a few pixels, but it's hard to pinpoint exactly.

The relevant CSS code is as follows:

#wrapper {
    max-width: 900px;
    min-width: 500px;
    width: 100%;
    margin: 0 auto;
    display: block;
}

#container {
    width: 100%;
    margin: 0 auto;
    position: relative;
    padding: 0;
    text-align: center;
}

#main {
    width: 100%;
    margin: 0 auto;
    float: left;
}

/* nav style */
#header, #footer, .pagination {
    margin: 0 auto;
    width: 100%;
    padding: 20px;
    left: 0;
    right: 0;
    text-align: center;
    float: left;
}

#menu-nav {
    margin: 0 auto;
    width: 100%;
    border-bottom: 1px solid;
    float: left;
    position: relative;
}

#menu-nav li, #footer li, .pagination li {
    padding: 20px;
    list-style: none; 
    display: inline-block;
    text-align: center;
}

#menu-nav a {
    display: block;
}

#menu-nav a, #menu-nav a:visited, #footer a, #footer a:visited, .pagination a, pagination a:visited, a, a:visited {
    text-decoration: none;
}

/* end nav style */

/* element styling */

h1 a {
    text-decoration: none;
    margin: 0 auto;
    text-align: center;
    padding-bottom: 15px;
}

#header {
    text-align: center;
    margin-top: 8px;
    width: 100%;
}

#header a {
    /*float: left; - uncomment to align logo with intro text */
    margin: 0 auto;
}

#header img {
    max-width: 150px;
    margin: auto;
}

#intro {    
    width: 35%;
    margin: 0 auto;
    text-align: left;
    padding-top: 30px;
    padding-bottom: 50px;
}

Here's the relevant HTML snippet:

<div id = "wrapper">
    <div id = "container">
        <div id = "header">
            <?php if ( get_theme_mod( 'logo-upload' ) ) : ?>
                <a href="<?php echo esc_url( home_url( '/' ) ); ?>" id="site-logo" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
                <img src="<?php echo get_theme_mod( 'logo-upload' ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
                </a>
            <?php else : ?>
                <h1><a href = "index.php"><?php echo get_theme_mod('title_textbox', 'Suburbia'); ?></a></h1>
            <?php endif; ?>

            <?php wp_nav_menu( array( 'Nav' => 'Nav' ) ); ?>               
        </div>
    </div>
</div>

Answer №1

The alignment of your header and footer is off because there is a padding of 20px on all sides. Adjust the padding left and right to 0 in order to align the divs properly.

#header, #footer, .pagination {
    padding: 20px; // Update this to the following
    padding: 20px 0;
}

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

How to perfectly align content on a webpage

Can someone help me understand why my webpage is off-centered as it scales up? I have set a minimum width of 1000px, but it still appears to be centered at 30%-70%. Any insights on this issue would be greatly appreciated. <!DOCTYPE html PUBLIC "-//W3 ...

Common problems encountered when web scraping

This question may seem simple, but I am new to web scraping and struggling to extract NFL Future prices from a website. Despite my efforts, the code I have written below does not return any results. Currently, I am aiming to retrieve the text of team names ...

Revamping HTML Label 'for' with JavaScript: Unveiling Effective Techniques

I'm facing an issue with changing the target of a label that is associated with a checkbox using JavaScript. Here's the code I have: <input type="checkbox" id="greatId" name="greatId"> <label id="checkLabel" for="greatId">Check Box&l ...

Remove the empty space between lines of images

Is there a way to remove the horizontal and vertical space between the squares? <div class="first"> <ul> <li><img src="http://dummyimage.com/40x40/111111/000000.jpg"/></li> <li><img src="http://dummyimage ...

html how to delete the beginning and end of hr element

There is a <hr noshade> tag in my HTML code which does not have any effect on the web view. However, when I print it to a PDF file, it shows head and tail like this: https://i.stack.imgur.com/TaBAc.jpg Here is my CSS that applies styling when print ...

A horizontal navigation bar featuring tabs that adjust their width automatically to ensure a consistent dimension across all

I'm aiming to create a horizontal menu that adjusts its width automatically to 100%. MY CSS .horizontal { width: 100%; } .horizontal ul { display: table; width: 100% } .horizontal li { display: table-cell; } .horizontal li a { height: 3 ...

Rebel Spirit on a Wordpress Platform

I've encountered a strange issue on my Wordpress blog. For some reason, the code "&nbsp" is being inserted right after the opening <body> tag. I have checked the header.php file and there is no instance of this code present there. It's ...

Javascript is utilized to populate text within a div, although the animation is exclusively applied to the initial text

I am currently working on designing a landing page that showcases a dynamic display of rotating texts with a typewriter-like animation effect. While I have successfully implemented the animation for the first text, I am facing an issue where the subsequent ...

Maintain a consistent header height with CSS even when using the calc() function

--dis: calc(var(--max-height) - var(--min-height)); /* @media large{--min-height:13rem}; @media small{--min-height:6.5rem}; --max-height:75vh; */ --percent: calc(var(--scroll-ani) / var(--dis)); /* in js: document.body.style = "--scroll-ani: ...

Utilizing form selectors in non-traditional elements

Trying to optimize my website by avoiding nested forms, I have multiple forms loaded via AJAX. Instead of nesting them, I plan to use select and checkbox selectors along with jQuery actions outside the form element. Here's what I have in mind: <di ...

Retrieve the content of a different page and store it as a variable using ajax

Is it possible to assign the content of another HTML page to a JavaScript variable? I attempted: var X = $(http://www.website.com/home).html() Unfortunately, this did not work, even though it seemed like a good idea. Can anyone provide guidance on how t ...

AngularJS - How to loop through a div to display all items

I am working with AngularJS to create a repeatable shopping cart items feature. Below is a sample JSON data structure: [{"src": "img/T1.jpg", "itemname": "solid green cotton tshirt", "style": "MS13KT1906", "colour": "Blue", "size": "s", "qty": "1", "price ...

Error in Blinking Tooltip when Hovering Skill Bubble (React and d3)

I've encountered a frustrating issue with tooltips on my website - they just won't stop blinking when I hover over the skill bubbles. I tried fixing the tooltips at a certain location, but whenever there's a bubble in that spot and I hover o ...

Tips for organizing JSON data in AngularJS are as follows:

Can someone assist me in looping this array value into 3 columns using angularjs? Currently, my view appears as an HTML table with 3 columns, but the values are displayed vertically instead of horizontally. You can see an example of how it looks here. Bel ...

HTML/CSS: Maintain Hover-Over Pop Up Boxes in Position Until Another Element is Hovered Over

Seeking HTML code to maintain a hover-over pop-up box in position on an image map until another section of the image map is hovered over. For example, refer to my code below - when hovering over a country on the map, a pop-up box with information about a ...

Exploring the process of including cube quantities in three.js code

In my current project, I am facing a challenge of incorporating multiple spheres into the scene. Initially, there were only three cubes present, but now I need to include around 10 spheres that are evenly spaced from each other and are rotating at varying ...

What is the solution for setting a regular height to a Bootstrap select when no option is currently selected?

On my webpage, I am incorporating bootstrap select and I want it to be empty initially with a value of "" when the page first loads. This is essential because it is a required field, so if a user attempts to submit the form without making a selec ...

Styling the React Material UI DataGrid with the MuiDataGrid-window class using createMuiTheme or makeStyles / styled-components

I've been putting in a lot of effort to customize the css for the .MuiDataGrid-window in MaterialUi's DataGrid. I've been referencing css rules from https://material-ui.com/api/data-grid/ I managed to get it working within createMuiTheme fo ...

Developing a form using ASP.NET with dual models

I am currently using Visual Studio 2017 with all the latest updates installed. I am facing a challenge where I need to create a form with text box answer questions and a checkbox answer question, and then store all the answers in a single database entry. M ...

Executing Controller method from an HTML webpage

I have designed a webpage in Html called SomePage.Html, and I am looking to trigger a method every time someone visits this page. Let's say I have a Controller named DefaultController with a method called - Get() and I want this method to be executed ...