简体   繁体   English

CSS边框和填充在IE 8 + 9中不起作用

[英]CSS border and padding not working in IE 8 + 9

I have the following DOM and CSS: 我有以下DOM和CSS:

var tableRow = jQuery(
    jQuery('<tr/>')
        .addClass('tr_class')
        .append(
            jQuery('<h3/>')
                .text('Title')
                .addClass('first_class second_class')
        )
).appendTo(table);


.tr_class{
    padding: 0px 0px 2px 5px;          /*not working*/
    display: block;                    /*not working*/
}


h3.first_class {
    font-weight: bold;                /*working*/
}


h3.second_class {
    border-bottom: 1px solid #5f7836; /*not working*/
    padding: 3px;                     /*not working*/
    display: block;                   /*not working*/
    font-size: 11px;                  /*working*/
}

In IE8 + 9, several of my CSS rules are not working. 在IE8 + 9中,我的一些CSS规则无法正常工作。

border , padding and display . borderpaddingdisplay

Can anyone explain why this might be? 谁能解释为什么会这样?

Here's a jsfiddle with the rendered HTML. 这是带有呈现的HTML的jsfiddle

UPDATE 更新

I appreciate all of the comments and suggestions, I'm going to look into fixing my mark up... 我感谢所有的评论和建议,我将研究如何修正我的标记...

ANOTHER UPDATE 另一个更新

You were all correct! 你们都是正确的! My horrendous mark up was the culprit here. 我的罪魁祸首是这里的罪魁祸首。 Everyone's input was much appreciated! 非常感谢大家的投入!

This is not only IE 8+ issue but it won't work in any browser. 这不仅是IE 8+的问题,而且在任何浏览器中都无法使用。

You can't have padding in table rows. 表格行中不能有填充。 Instead you need to add the padding styles in your td . 相反,您需要在td添加填充样式。

And I can't see that you're appending any td in your code so I could modify that. 而且我看不到您在代码中附加了任何td ,因此可以对其进行修改。

Thus, ensure to put padding styles in your td instead of tr . 因此,请确保将填充样式放在td而不是tr

And just be ensure to put td in your tr and do the rest things like border and anything you want on it. 并且只需确保将td放入tr然后执行其余操作,例如border和任何您想要的内容。

  • Several css properties, padding and border among them, are invalid when applied to tr elements 几个css属性(其中的paddingborder在应用于tr元素时无效

  • You are nesting an h3 directly under a tr , which is invalid HTML. 您将h3直接嵌套在tr之下,这是无效的HTML。 tr elements may only directly contain th or td . tr元素只能直接包含thtd

IE 8+使用CSS样式:边框,填充和显示,可能是HTML结构中的问题。

My first thought is that you have the HTML tags wrong. 我首先想到的是您的HTML标记错误。 It is 它是

<tr> and <h3> for starting a tag, and </tr> and </h3> for closing/ending a tag.

The second is the sytnax of the jQuery you are using. 第二个是您正在使用的jQuery的语法。 Try the more modern syntax, such as: 尝试使用更现代的语法,例如:

$('tr') instead of JQuery('<tr>').

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

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