tags:

views:

124

answers:

4

I have an html table within a div of a specific size. I want the table to apply margin collapse and be 100% wide. Here is my code. It renders how I want it to in IE8 and incorrectly in Firefox. Firefox may be doing the spec correctly, but whatever. How do I fix my css to work in both browsers?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>

<style type="text/css">
table
{
    border-collapse: collapse;
    border-spacing: 0;
}

table
{
    width: 100%;
    display: block; 
}

td, th
{
    border: 1px solid #000000;
}

</style>
</head>

<body>

<div style="width: 600px; border: 1px purple solid;">
<table>
    <tr>
        <th></th>
        <th>Header 1</th>
        <th>Header 2</th>
        <th>Header 3</th>
    </tr>
    <tr>
        <td>Label 1</td>
        <td>1.A</td>
        <td>1.B</td>
        <td>1.c</td>
    </tr>
    <tr>
        <td>Label 2</td>
        <td>2.A</td>
        <td>2.B</td>
        <td>2.c</td>
    </tr>
</table>
</div>

</body>

</html>

I need the display:block for margin collapsing to work in Firefox.

A: 

Okay, this is my first post on Stack Overflow, and I believe I have solved your issue. All I did was change the line "display: block;" to "display: relative;" and that seemed to have fixed the "stretching" issue.

I am using Chromium and I understood what you mean when the tables weren't stretching out as they were in Internet Explorer. I know Chromium and Firefox handle pages pretty similar, so that might have resolved your issue.

John Mollman
A: 

just remove the display: block;, the border-collapse works fine

y34h
A: 

I posted a new question with some further clarification: http://stackoverflow.com/questions/3809804/css-table-width100-displayblock-not-working-in-firefox

I couldn't edit this question.

@y34h: I need the display:block because that causes firefox to use collapsing-margins on the table element.

@John Mollman: Setting display:relative; does allow 100% width, but it is not a solution for 2 reasons: (A) display:relative; isn't an allowable attribute for the display item. I'm assuming that the firefox parser just ignores the style. (B) Because the style gets ignored, we run into the same problem as with y34h's answer.

Thanks for the effort though!

Maggie
A: 

I'm just wondering.. If you're specifying div width="600" and then require the table to fit 100%.. Why not put a width on the table instead of the containing div.
don't mind me, Just curious to know what specifically you're trying to achieve other than the border-collapse.

conqenator