简体   繁体   English

使用CSS的填充表在IE上不起作用

[英]Padding table with CSS doesn't work on IE

This is not working on my IE: 这不适用于我的IE:

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

however it works on Opera. 但它适用于Opera。

Is there a workaround? 有解决方法吗?

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. 早期的CSS规范(IE6遵循 - 我使用“松散地跟随”这个词)并不清楚表格中定义的填充应该是什么意思。 IE6, naturally, decided to interpret this differently than every other browser, by ignoring the padding. IE6当然决定通过忽略填充来解释与其他浏览器不同的解释。 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. 到IE7问世的时候,规格已经像其他浏览器一样清理,但IE6仍然存在问题,它只是忽略了填充。

The best solution is to avoid putting padding on your table, but instead surrounding it with a div, and putting the padding there. 最好的解决方案是避免在桌面上放置填充,而是用div包围它,然后将填充物放在那里。

<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). 当然,如果你想要的是单元格间距或单元格填充(而不是仅仅填充表格),那么你应该使用cellspacingcellpadding属性(即使你不想要这些,你至少需要cellspacing="0"以避免IE6表呈现的另一个单独问题)。

Also, the inline styles here are for demo purposes; 此外,此处的内联样式仅用于演示目的; using css classes is generally considered better practice. 使用css类通常被认为是更好的做法。

Did you try using <table cellpadding="5"> ? 你尝试过使用<table cellpadding="5">吗? IE has problems with some css styling. IE在某些CSS样式方面存在问题。 Also your syntax is wrong you forgot a semi-colon. 你的语法错了,你忘记了分号。

I'd venture to guess something else is wrong in your code. 我冒昧地猜测你的代码中有其他错误。

Padding works fine in IE: 填充在IE中工作正常:

http://jsbin.com/ewuho4/ http://jsbin.com/ewuho4/

If you want to pad the cells then use cellpading attribure (cellpadding="X") if you want to padd a table, then that is awkward considering it's structure, I recommend that you put a margin if you want some space between it and the rest of stuff. 如果你想填充单元格然后使用cellpading属性(cellpadding =“X”),如果你想填充一个表,那么考虑到它的结构这是很尴尬,我建议你如果你想要它和剩下的东西。 Padding does not work on IE an even though I am not a fan of IE I do not blame it for that 即使我不是IE的粉丝,填充也无法在IE上运行我不会因此而责备它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM