show/hide html table columns using css

后端 未结 4 1134
野性不改
野性不改 2020-12-01 07:29

I want to display a basic html table with controls to toggle showing/hiding of additional columns:

4条回答
  •  天涯浪人
    2020-12-01 08:17

    I don't think there is anything you can do to avoid what you are already doing, however, if you are building the table on the client with javascript, you can always add the style rules dynamically, so you can allow for any number of columns without cluttering up your css file with all those rules. See http://www.hunlock.com/blogs/Totally_Pwn_CSS_with_Javascript if you don't know how to do this.

    Edit: For your "sticky" toggle, you should just append class names rather than replacing them. For instance, you can give it a class name of "hide2 hide3" etc. I don't think you really need the "show" classes, since that would be the default. Libraries like jQuery make this easy, but in the absence, a function like this might help:

    var modifyClassName = function (elem, add, string) {
    var s = (elem.className) ? elem.className : "";
    var a = s.split(" ");
    if (add) {
      for (var i=0; i

提交回复
热议问题