Author Topic: CSS - Div/Table align problem in Firefox  (Read 2506 times)

0 Members and 1 Guest are viewing this topic.

Offline Tabuu

  • Hero Member
  • *****
  • Male
  • Posts: 809
    • http://tabuu-lion.artistsworld.org
CSS - Div/Table align problem in Firefox
« on: November 27, 2005, 10:00:21 am »
I've made a mock-up page layout, which I have coded to XHTML 1.0 Strict standards, using CSS properties to align each container(both divs and tables). When I view the page in Internet Explorer everything turns out perfectly, yet when I view the webpage in Firefox the alignment of the tables and divs are broken.

http://tabuu-lion.furtopia.org/test/test1.html

The topbar is supposed to have the menu and top content centered like
this
but it despite the css positioning it still ends up to the left like
this

The sidebar is supposed to be centered in its own table cell like
this
but it ends up left like
this

The coding itself seems to check out in every way, but have I done something wrong? Is there some sort of workaround I need? Or is the desired result even attainable through CSS?

I'd hope to find a solution that doesn't involve use of any depreciated html attributes (align="center" for example) and uses CSS instead. Thank you all.
|| Trades - OPEN! || Request - Considering A Few... || Commissions - Not that good yet -_- ||

|| DA || ArtistsWorld ||

Offline Nocte

  • Hero Member
  • *****
  • Male
  • Posts: 1689
    • http://unicorn.furtopia.org/
CSS - Div/Table align problem in Firefox
« Reply #1 on: November 27, 2005, 12:29:36 pm »
If you want to center a block element (such as a nested table), use "margin: 0px auto". You'll have to add that one to the style of tbbox and sbtable.

IE doesn't understand "auto". Fortunately, there's a workaround because IE also misinterprets "text-align" (as you already found out '<img'> ).

(For XHTML/CSS, it is recommended to use tables only for, well, tables. For layout tricks, it is preferred to use div/span and CSS.)
Drawing tutorial
Avatar information
FEHu3a A+ C D-- H M- P R++ T W-- Z Sm- RLCT a cl++++ d+ e+++ f- h+++ i++ j p sm*

Offline Tabuu

  • Hero Member
  • *****
  • Male
  • Posts: 809
    • http://tabuu-lion.artistsworld.org
CSS - Div/Table align problem in Firefox
« Reply #2 on: November 27, 2005, 10:00:09 pm »
Thanks Nocte. I figured you would be the one to step up to bat. I've actually heard something about margins, but I wasn't really sure what was meant. I think I understand now, though. And as far as the tables go, I have been trying to fix the bad habit of using them as containers. Sadly I cannot seem to figure out how to make containers with both headers and bodies, or do the menu things I have without using tables to achieve the same asthetic effect (though my table usage has declined dramatically) Do you have any suggestions on how I might manage that?
|| Trades - OPEN! || Request - Considering A Few... || Commissions - Not that good yet -_- ||

|| DA || ArtistsWorld ||

Offline Nocte

  • Hero Member
  • *****
  • Male
  • Posts: 1689
    • http://unicorn.furtopia.org/
CSS - Div/Table align problem in Firefox
« Reply #3 on: December 02, 2005, 04:28:24 pm »
It can be hard indeed, especially to get it working on the major browsers.  The best way to make a header with a certain number of boxes centered is to embed three divs; the outer one will span the entire width of the screen, the middle one is shrinkwrapping the link/menu boxes (and is centered), and the links themselves are block elements with a fixed width.  (If it's not necessary they all have the same width, it's easier to use inline elements, like a <span>.)

Now the trick is to put the block elements side by side, instead of the usual top-down. The official way is to specify "display: inline-block". Unfortunately, this won't work in Firefox or Mozilla (for a change! ). Alternatively, you can add "float: left", but this isn't ideal either. The outer div will no longer be wrapped around the floated elements, so you can't outline it anymore. (You can experiment with setting the height explicitly, but be careful not to break the layout if someone selects a bigger or smaller font).  Yet another option is to use "display: table-cell". This will make your elements behave almost like an inline block. It's not elegant, but works almost everywhere.

If you are still having troubles to center block elements, there's a very dirty trick that works in most browsers. If your element is say 300 pixels wide, use "left: 50%; margin-left: -150px". You move the left edge to 50% by absolute positioning, and then move it back half of its width.
Drawing tutorial
Avatar information
FEHu3a A+ C D-- H M- P R++ T W-- Z Sm- RLCT a cl++++ d+ e+++ f- h+++ i++ j p sm*

Offline Reathion_Arkidian_Nights

  • Newbie
  • *
  • Posts: 16
CSS - Div/Table align problem in Firefox
« Reply #4 on: February 12, 2006, 12:35:09 am »
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en" xml:lang="en">
<head>
 <style type="css/txt">
<!--

.toplinks {
   z-index: 1000;
        left: 8px;
        top: 80px:
        display: block;
        font-family:"Arial Black", Arial, "Arial Narrow", "Times New Roman";
   font-size: 10px;
   margin: 25px 0px 0px 0px;
   padding: 0 0 0 70px;
        color: #ffffff;
}

.menu {
   font: 12px Arial, Helvetica, sans-serif;
   padding-top: 10px;
   padding-bottom: 10px;
   margin: 0px;
   color: #ffffff;
}

.menu a, .pageList .this-page {
   padding: 2px 6px;  
   border: solid 1px #444444;
   background: #000033;
   text-decoration: none;
}

.menu a:visited {
   padding: 2px 6px;
   border: solid 1px #444444;
   background-color:#000033;
   text-decoration: none;
}

.menu .break {
   padding: 2px 6px;
   border: none;
   background: #444444;
   text-decoration: underline;
}

.menu .end {
   padding: 2px 6px;
   border: solid 2px #000000;
   background: #444444;
}

.menu .this-page {
   padding: 2px 6px;
   border-color: #999;
   font-weight: bold;
   font-size: 13px;
   background: #444444;
}

.menu a:hover {
   color: #ffffff;
   background: #555555;
   border-color: #000000;
   text-decoration: none;
   
}

.menu .ranking {
   display: block;
   margin-top: 10px;
   font-weight: bold;
}

.menu .ranking a {
   padding: 0;
   border: 0;
   background:#444444;
}

.menu .ranking a:hover {
   text-decoration: underline;
   color: #FFFFFF;
   background: transparent;
}

-->
</style>

</head>
<body>

<!-- Start of Menu -->

<div class="toplinks">
      <div class="menu">
        <a href="Index.htm" target="_self">HOME</a>
         <a href="aboutme.htm" target="_self">About Me</a>
         <a href="name@isp.com" target="_self">email</a>
       </div>
</div>

<!-- End of Menu -->

<!-- Start of Content -->

[ Content goes here ! ]

<!-- End of Content -->
</body>
</html>

------------------------------------------------
I hope this will help! '<img'>

Offline Obsydian

  • Hero Member
  • Species: Cabbit
  • Fluffy Cabbit
  • *****
  • Female
  • Posts: 711
    • LunaCrystal Creations
CSS - Div/Table align problem in Firefox
« Reply #5 on: February 12, 2006, 12:37:01 am »
I was going to say it looked fine in my Firefox, but then I realized that you might have just fixed it.  '<img'>
Syd | She/They | 30s