views:

738

answers:

4

I found many answers to this question on Google, but none of them seem to work for all browsers.

I am looking for a CSS-only way to get min-width working on Firefox, IE6, IE7, and IE8. It is well-known that IE does not support min-width, so several hacks are out there to try to emulate the behavior of min-width. Unfortunately, I have not had any luck with them.

Specifically, this is what I'm trying to do:

<style type="text/css">
    table.dataTable td {
        white-space: nowrap;
    }

    table.dataTable td.largeCell {
        white-space: normal;
        min-width: 300px;
    }
</style>

<table class="dataTable">
    <tr>
        <td>ID</td>
        <td>Date</td>
        <td>Title</td>
        <td class="largeCell">A large amount of data like a description that could span several lines within this cell.</td>
        <td>Link</td>
</table>

Does anyone have a way to get this to work?

A: 

You'll have to adjust your markup, but Brian Huisman's CSS min-height hack has served me well so far in IE 6,7, and (I think) 8.

lance
Amazingly, this solution (adjusted for width instead of height) works nicely on IE6 and FF. IE8 is still giving me trouble, though. Any thoughts on this?I will edit my question to include exactly what I tried.
Aaron
What's amazing is that I read your question twice and saw "min-height" both times. I don't have any experience using it for width. I'm sorry I couldn't be more helpful.
lance
+1  A: 

I use:

min-width: 200px;
_width: 200px; /* IE6 */
fire
Is `_width` an IE6-only recognized css value? Unfortunately, this didn't work for me.
Aaron
yes you can use _anything to declare an IE6 only property, that was in the days of IE6 hacks however I would recommend you use conditional comments nowdays
fire
A: 

So it turns out that the necessary hack for getting min-width to work in all browsers isn't as ugly as many make it out to be.

All I had to do was add CSS for a div within the largeCell and add an empty div at the end of the cell. The div is only 1px tall, so it doesn't really make the cell look larger than it should be.

<style type="text/css">
    table.dataTable td {
        white-space: nowrap;
    }

    table.dataTable td.largeCell {
        white-space: normal;
        min-width: 300px;
    }

    table.dataTable td.largeCell div {
        margin: 0px 0px 0px 0px;
        height: 1px;
        width: 300px;
    }
</style>

<table class="dataTable">
    <tr>
        <td>ID</td>
        <td>Date</td>
        <td>Title</td>
        <td class="largeCell">A large amount of data like a description that could span several lines within this cell.<div></div></td>
        <td>Link</td>
</table>
Aaron
A: 
<style type="text/css">
.table1 th a {
    display:inline-block;
    width:200px";
}
</style>

<table>
    <tr>
        <th><a>title1</a></th>
        <th><a>title2</a></th>
    </tr>
    <tr>
        <td>text</td>
        <td>text</td>
    </tr>
</table>
y34h