how to revert back to normal after display:none for table row

前端 未结 9 1017
迷失自我
迷失自我 2020-12-11 14:42

Basically, I have a table. Onload, I set each row of the table to display:none since I have a lot of javascript processing to be done and I don\'t want user to

相关标签:
9条回答
  • 2020-12-11 14:54

    I know this is an old question, but still got here searching the answer to the same question.

    You can set displays for non table elements like this:

     display: table;
     display: table-cell;
     display: table-column;
     display: table-colgroup;
     display: table-header-group;
     display: table-row-group;
     display: table-footer-group;
     display: table-row;
     display: table-caption;
    

    This works with table elements to. I had a similar issue with a <th> element, and fixed it with display : table-header-group;.

    I tested the result in Chrome, Firefox, Safari and it works.

    You can read more here : https://css-tricks.com/almanac/properties/d/display/

    0 讨论(0)
  • 2020-12-11 14:58

    I was unable to comment, which seems counterproductive. Ray's answer above also fixed my issue. I had a javascript to hide table rows where a search string does not match the contents of one of the cells.

    The example javascript code I used had display = "block" for the rows which remain displayed (display = "none" for the rows to hide).

    My search result left only the matching rows displayed, but lost the table formatting, so that all the TDs ran together instead of being formatted in columns. So the table started out with the correct columns, but lost them as soon as the search changed the display property.

    Simply changing display = "block" to display = "" fixed it.

    0 讨论(0)
  • 2020-12-11 14:59

    When switching between hiding and showing TRs using toggleClass, the following will work:

    display:none;
    

    and

    display: table-row;
    

    E.g.

    $('#the_tr_id').toggleClass('tr_show','tr_hide');
    

    Where:

    .tr_hide {
        display:none;
    }
    
    .tr_show {
        display: table-row;
    }
    
    0 讨论(0)
  • 2020-12-11 15:05

    Why don't you put the table in a div, make that div's display to none, and when the processing is done, set div's display back to block or inline block or whatever you need there...

    0 讨论(0)
  • 2020-12-11 15:07

    set display to an empty string - this will allow the row to use its default display value and so works in all browsers

    0 讨论(0)
  • 2020-12-11 15:08

    Use visibility instead of display for your case.

    visibility: hidden;

    after load

    visibility: visible;

    find out more here

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