How do I text-align center, when floating left?

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

How do I text-align center, when floating left?

Post by simonmlewis »

I am trying to line up DIVs, but to get them centered inside another DIV. So rather than lining up from the left, they are horizonally centered. I'm sure it's easy to do, but having trouble seeing how.....

Code: Select all

<style>

.subcat_topboxes
{ width: 250px;
float: left;
}
</style>

echo "<div style='text-align: center'>";
$result = mysql_query ("SELECT name, photo, information FROM subcategories WHERE catid = '$catid'");
while ($row = mysql_fetch_object($result))
      {
      echo "<div class='subcat_topboxes'><img src='/images/pages/$row->photo' /><br/>$row->name<br/>$row->information</div>";
      }
      	mysql_free_result($result);
      	echo "<div style='clear: both' /></div></div>";

Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How do I text-align center, when floating left?

Post by Christopher »

I would recommend putting all the subcat_topboxes divs in a wrapper div, and then centering that inside your outer div.
(#10850)
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I text-align center, when floating left?

Post by simonmlewis »

Code: Select all

echo "<div style='text-align: center'>";
This is the wrapper div. Centered.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How do I text-align center, when floating left?

Post by Christopher »

That centers what is inside of it. It does not center the wrapper div. That's why I recommended wrapping the subcat_topboxes with another div inside your current wrapper.
(#10850)
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I text-align center, when floating left?

Post by simonmlewis »

Sorry I don't understand.
The Wrapper has an internal text-align center, so would have thought anythign in there would be centered. Plus it's not got a width set so goes full width.

Can you show me what you mean please.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply