Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 208273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:48:38+00:00 2026-05-11T17:48:38+00:00

I have been looking around for solutions, and tried to implement what is often

  • 0

I have been looking around for solutions, and tried to implement what is often suggested, but I am not managing to horizontally center a div within another div.

With my CMS I want to show up to four info blocks towards the bottom of the page. So, I am trying to put between zero and four divs within two container divs. The four divs get a width of 19%, 33% or 49% of the available width dependent on how many divs are shown on a page. The inner container is supposed to be horizontally centered within the outer container. Thereby, the group of up to four divs should of course end up in the horizontal center. Since the inner container is the same width as the main content plus two columns above it, which are centered, it should appear in line vertically. The outer container takes the full page width and has a background image.

My code is now as follows:

<!-- BEGIN USER MODULES -->
<tr>
  <td align="left" valign="top">

    <?php if ( $this->countModules( 'user1 and user2' ) || $this->countModules( 'user1 and user3' ) || $this->countModules( 'user1 and user4' ) || $this->countModules( 'user2 and user3' ) || $this->countModules( 'user2 and user4' ) || $this->countModules( 'user3 and user4' ) ) : ?>
        <style type="text/css">#user1, #user2, #user3, #user4 { width:49%; }</style>
    <?php endif; ?>
    <?php if ( $this->countModules( 'user1 and user2 and user3' ) || $this->countModules( 'user1 and user2 and user4' ) || $this->countModules( 'user1 and user3 and user4' ) || $this->countModules( 'user2 and user3 and user4' ) ) : ?>
        <style type="text/css">#user1, #user2, #user3, #user4 { width:33%; }</style>
    <?php endif; ?>
    <?php if ( $this->countModules( 'user1 and user2 and user3 and user4' ) ) : ?>
        <style type="text/css">#user1, #user2, #user3, #user4 { width:19%; }</style>
    <?php endif; ?>

    <?php if ($this->countModules( 'user1 or user2 or user3 or user4' )) : ?><div id="wrap1234"><div id="user1234">
        <?php if($this->countModules('user1')) : ?><div id="user1" class="module_bc"><jdoc:include type="modules" name="user1" style="xhtml" /></div><?php endif; ?>
        <?php if($this->countModules('user2')) : ?><div id="user2" class="module_bc"><jdoc:include type="modules" name="user2" style="xhtml" /></div><?php endif; ?>
        <?php if($this->countModules('user3')) : ?><div id="user3" class="module_bc"><jdoc:include type="modules" name="user3" style="xhtml" /></div><?php endif; ?>
        <?php if($this->countModules('user4')) : ?><div id="user4" class="module_bc"><jdoc:include type="modules" name="user4" style="xhtml" /></div><?php endif; ?>
    </div><div class="clear"></div></div><?php endif; ?>

    </td>
</tr>

In my style sheets I have this:

#wrap1234 { background:transparent url(images/header_bg.png) no-repeat scroll 0 0; border-bottom:1px solid #444444; border-top:1px solid #444444; margin:25px 0 10px; padding:5px 0; text-align:center; align:center;}

#user1234 { width:1420px; margin-left:auto; margin-right:auto; }

#user1, #user2, #user3, #user4 { float:left; margin:5px 0; padding:5px 0; text-align:left; }

The table and body in which all this is placed are as follows, skipping everything that falls outside of the direct hierarchical line:

<body><div id="wrapper_main"><center><table border="0" cellpadding="0" cellspacing="0" width="<?php echo $this->params->get('width'); ?>" id="main_table"><tbody> 

The css of the body and table is below. Using Firebug I cannot find anything in there that makes a difference when switched off.

html, body, form, fieldset{margin:0; padding:0;}
body {background:#222222 none repeat scroll 0 0; color:#777777; font-family:Helvetica,Tahoma,sans-serif; font-size:0.72em; height:100%; text-align:center;}
#wrapper_main {background:#FFFFFF url(images/wrapper_main_bg.gif) repeat-x scroll left top; border-bottom:2px solid #CCCCCC; padding-bottom:20px; position:relative; width:100%; z-index:1;}
td, div {font-size:100%;}

The actual page is available on my development site at jldev d o t joomlaloft.com.

As you can see, I have given the inner container a fixed width as well as left and right margin auto, as is often suggested as the way to center a div horizontally. However, the inner container with the divs in it ends up left aligned.

Can this be made to work? Or, should I try an alternative, for example by putting a variable margin left and right on the most left and most right info block divs?

I have seen that there are many very good answers on stackoverflow so I am hoping that someone is able to tell me where I went wrong. As it is I am out of inspiration… Many thanks in advance for any help you can give!

PS Btw this must be one of the most intuitive and practical forums I have ever seen!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:48:38+00:00Added an answer on May 11, 2026 at 5:48 pm

    The inner centered div cannot be wider than it’s containing div. In my browser your site is 1200 px wide and the #user1234 is 1420px;

    Set #user1234 to width: 90%; and each user div to width: 25%; when there are 4 divs. Put overflow:hidden; on #user1234 to clear the floats.

    It does not look like the #user1234 div is centered because the #user4 div text does not fill the available space. Put background-color:#c00; on #user1234 to see where it’s boundaries are. (note: you must have overflow:hidden otherwise #user1234 does not have a height and you will not see the background-color).

    Re: previous comment – There are no problems with using width and margin on the same tag.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 334k
  • Answers 334k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can try WixEdit. May 14, 2026 at 3:18 am
  • Editorial Team
    Editorial Team added an answer What is the problem? Certainly the comparison is correct. Here… May 14, 2026 at 3:18 am
  • Editorial Team
    Editorial Team added an answer Use JSON. JSON is a lightweight data-interchange format which makes… May 14, 2026 at 3:18 am

Related Questions

I am the programmer for the Education department at a county hospital. I would
I am looking for some input on something I have been thinking about for
I'm building an app which is going to have to handle and store a
This was an interview question. Given Visual Studio 2008 and an icon saved as

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.