views:

17070

answers:

7

So I just love it when my application is working great in Firefox, but then I open it in IE and... Nope, please try again.

The issue I'm having is that I'm setting a CSS display property to either none or table-cell with JavaScript.

I was initially using display: block, but Firefox was rendering it weird without the table-cell property.

I would love to do this without adding a hack in the JavaScript to test for IE. Any suggestions?

Thanks.

+2  A: 

Well, IE7 does not have display: table(-cell/-row) so you will have to figure something else out or do browser targeting (which I agree, is bad hack). As a quick fix (I don't know what you're trying to achieve, appearance-wise) you could try display: inline-block and see what it looks like.

Maybe figure out a way to do display: block and solve the problem of "Firefox rendering it weird" instead? Can you describe what you mean by the weird rendering exactly?

joelhardi
When you set it to block in Firefox, it renders the table cells on top of each other instead of side by side.I would rewrite the whole thing to use DIVs instead, but I'm far to lazy for that, so I just wrote the sh**ty hack code instead.
Ryan Smith
Cool, what does the markup look like?
joelhardi
If you are doing block-level elements of some kind, you could set them to float "float: left" so in Firefox they will stack up next to each other instead of in rows. Or "display: inline-block" might work here, but in IE7 it can only be used on elements that would normally be inline, like a or em.
joelhardi
+2  A: 

You never need Javascript to test for IE, use conditional comments.

You might look at the solution these guys came up with for handling table-like display in IE.

eyelidlessness
A: 

just a suggestion, if you're trying to use table-cell to vertically align text in IE 6/7, try using line-height to bump the content down to the middle.

alex
It works as long as the content fits in one line.
Török Gábor
+1  A: 

I've been using CSS for over a decade and I've never had occasion to use display:table-cell, and the only times I ever use conditional comments are to hide advanced effects from IE6.

I suspect that a different approach would solve your problem in an intrinsically cross-browser way. Can you open a separate question that describes the effect you're trying to achieve, and post the HTML and CSS that's currently working in Firefox?

Herb Caudill
+10  A: 

A good way of solving this setting the display value to '':

<script type="text/javascript">
<!--
function toggle( elemntId ) {
    if (document.getElementById( elemntId ).style.display != 'none') {
        document.getElementById( elemntId ).style.display = 'none';
    } else {
        document.getElementById( elemntId ).style.display = '';
    }
    return true;
}
//-->
</script>

The empty value causes the style to revert back to it's default value. This solution works across all mayor browsers.

Jacco
+1  A: 

I had the same issue and used

*float: left;

"*" indicates IE only

Jonathan Hendler
Really? That's a pretty cool trick.
Ryan Smith
To be precise, the `*` (asterisk) hack addresses IE 7 and below.
Török Gábor
Star and underscore hacks: http://www.ejeliot.com/blog/63
Artem Russakovskii
+1  A: 

Why do people recommend not using when DIVs are f*cking broken in half the browsers out there?

If I can't use table and I can't use display:table-cell, then how am I supposed to line up 3 block items horizontally?

df