Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Padding table with CSS doesn't work on IE

This is not working on my IE:

<table style="padding:5px">...</table>

however it works on Opera.

Is there a workaround?

like image 691
fabio Avatar asked Jan 25 '11 16:01

fabio


People also ask

How do I padding a table in CSS?

Complete HTML/CSS Course 2022 Cell padding is the space between cell borders and the content within a cell. To set cell padding in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <table> tag, with the CSS property padding.

Can we give padding to table?

HTML tables can adjust the padding inside the cells, and also the space between the cells.

What is the CSS replacement for table cellpadding?

The cellpadding is replaced by the padding property on the <td> element.

What does the padding CSS property do for a table?

The CSS padding properties are used to generate space around an element's content, inside of any defined borders. With CSS, you have full control over the padding. There are properties for setting the padding for each side of an element (top, right, bottom, and left).


2 Answers

The earlier CSS specs (which IE6 follows -- and I use the word "follows" loosely) are not clear about what padding defined on a table should even mean. IE6, naturally, decided to interpret this differently than every other browser, by ignoring the padding. Other browsers decided to render it by adding spacing between the table border and the outermost cells, without affecting the spacing inside cells, or between internal cells. By the time IE7 came out, the specs had cleared up to work like the other browsers, but IE6 still has the problem, where it simply ignores the padding.

The best solution is to avoid putting padding on your table, but instead surrounding it with a div, and putting the padding there.

<div style="padding: 5px;">
    <table...>
    </table>
</div>

Of course, if what you want is cell spacing or cell padding (as opposed to just padding on the table), then you should use the cellspacing or cellpadding attributes (even if you don't want these, you at least need cellspacing="0" to avoid another separate issue with IE6 table rendering).

Also, the inline styles here are for demo purposes; using css classes is generally considered better practice.

like image 108
Ben Lee Avatar answered Oct 21 '22 03:10

Ben Lee


Did you try using <table cellpadding="5">? IE has problems with some css styling. Also your syntax is wrong you forgot a semi-colon.

like image 20
Valandres Avatar answered Oct 21 '22 04:10

Valandres