first-child and last-child with IE8

前端 未结 3 1038
甜味超标
甜味超标 2020-12-08 02:06

I have some css for adjusting things in my table.

Here it is:

.editor td:first-child
{
    width: 150px; 
}

.editor td:last-child input,
.editor td         


        
相关标签:
3条回答
  • 2020-12-08 02:30

    If you want to carry on using CSS3 selectors but need to support older browsers I would suggest using a polyfill such as Selectivizr.js

    0 讨论(0)
  • 2020-12-08 02:38

    Since :last-child is a CSS3 pseudo-class, it is not supported in IE8. I believe :first-child is supported, as it's defined in the CSS2.1 specification.

    One possible solution is to simply give the last child a class name and style that class.

    Another would be to use JavaScript. jQuery makes this particularly easy as it provides a :last-child pseudo-class which should work in IE8. Unfortunately, that could result in a flash of unstyled content while the DOM loads.

    0 讨论(0)
  • 2020-12-08 02:39

    If your table is only 2 columns across, you can easily reach the second td with the adjacent sibling selector, which IE8 does support along with :first-child:

    .editor td:first-child
    {
        width: 150px; 
    }
    
    .editor td:first-child + td input,
    .editor td:first-child + td textarea
    {
        width: 500px;
        padding: 3px 5px 5px 5px;
        border: 1px solid #CCC; 
    }
    

    Otherwise, you'll have to use a JS selector library like jQuery, or manually add a class to the last td, as suggested by James Allardice.

    0 讨论(0)
提交回复
热议问题