Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 更改第二列的颜色_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 更改第二列的颜色

Javascript 更改第二列的颜色,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有一个jQuery响应表。 缩小浏览器窗口时,可以看到不同的布局 我想更改每个表的第二列值的颜色,但我不知道如何为第二列值指定ID并更改其颜色 在下面提供一个和我的代码: #page-wrap { margin: 50px; } /* Generic Styling, for Desktops/Laptops */ table { width: 100%; border-collapse: collapse; } /* Zebra

我有一个jQuery响应表。
缩小浏览器窗口时,可以看到不同的布局

我想更改每个表的第二列值的颜色,但我不知道如何为第二列值指定ID并更改其颜色

在下面提供一个和我的代码:

#page-wrap {
    margin: 50px;
}
/* 
        Generic Styling, for Desktops/Laptops 
        */
 table {
    width: 100%;
    border-collapse: collapse;
}
/* Zebra striping */
 tr:nth-of-type(odd) {
    background: #eee;
}
th {
    background: #1a4567;
    color: white;
    font-weight: bold;
}
td, th {
    padding: 6px;
    border: 1px solid #ccc;
    text-align: left;
}
/* 
        Max width before this PARTICULAR table gets nasty
        This query will take effect for any screen smaller than 760px
        and also iPads specifically.
        */
 @media only screen and (max-width: 760px), (min-device-width: 768px) and (max-device-width: 1024px) {
    /* Force table to not be like tables anymore */
    table, thead, tbody, th, td, tr {
        display: block;
    }
    /* Hide table headers (but not display: none;, for accessibility) */
    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    tr {
        border: 1px solid #ccc;
    }
    td {
        /* Behave  like a "row" */
        border: none;
        border-bottom: 1px solid #eee;
        position: relative;
        padding-left: 50%;
    }
    td:before {
        /* Now like a table header */
        position: static;
        /* Top/left values mimic padding */
        top: 6px;
        left: 6px;
        width: 45%;
        padding-right: 10px;
        white-space: nowrap;
    }
    /*
            Label the data
            */
    td:nth-of-type(1):before {
        content:"BOM Id";
    }
    td:nth-of-type(2):before {
        content:"Brand Name";
    }
    td:nth-of-type(3):before {
        content:"BOM Type";
    }
    td:nth-of-type(4):before {
        content:"BOM Description";
    }
    td:nth-of-type(5):before {
        content:"Edit";
    }
    td:nth-of-type(6):before {
        content:"Related";
    }
    td:nth-of-type(7):before {
        content:"Print";
    }
    td:nth-of-type(8):before {
        content:"ECO";
    }
    td:nth-of-type(9):before {
        content:"Dev";
    }
    td:nth-of-type(10):before {
        content:"Files";
    }
}
/* Smartphones (portrait and landscape) ----------- */
 @media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
    body {
        padding: 0;
        margin: 0;
        width: 320px;
    }
}
/* iPads (portrait and landscape) ----------- */
 @media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
    body {
        width: 495px;
    }
}

如果您只想为第二列着色,可以使用类似于:

td:nth-child(2) {
    background: #CCC
}
th:nth-child(2) {
    background: teal
}

-更改第二列的颜色


如果还希望包含标题本身,则可以将其添加到
th
,类似于:

td:nth-child(2) {
    background: #CCC
}
th:nth-child(2) {
    background: teal
}

-也更改第二列标题的颜色


如果要为第二列(而不仅仅是第二列)着色,可以使用奇数和偶数,如下所示:

th:nth-child(even) {
    background: teal;
}

td:nth-child(even) {
    background: #CCC;
}

-对每一列应用颜色



仅适用于每个表的第二列

td:nth-child(2),th:nth-child(2){}

为了确保在早期IE中是否有效,这里有一个适合您的请求。我已经清理了它,并在CSS中添加了两行


您提到您不知道如何为分辨率较小的设备的第二列指定ID。例如,第一列的选择器为
td:before
,第二列的选择器为
td
。更具体地说,以下CSS似乎完成了您所寻找的目标:

@media only screen and (max-width: 760px) {
   td {
      color:orange;
   }

   td:before {
      color:darkblue; 
   }
}

从响应转换中,第一列实际上来自
td:before
上的contentCSS属性,而不是
th
标记。从语义的角度来看,这是错误的,但我猜你有限制迫使这种行为。

这应该有帮助发布不起作用的jsfiddle的目的是什么?@broading不是为了展示他所做的尝试,并让回答者有机会尝试修复它,而不必构建他们自己的整个fiddle?@ErikE我想说,粘贴代码而不努力正确设置jsfiddle的目的是什么。我的意思是至少把javascript代码放在javascript字段中。顺便说一句,这不是这个用户第一次这样做。“这只是我个人的意见,谢谢你的更正,”他说。显然,我并没有点击链接。我的错误。现在我知道你所说的“不工作的JSFIDLE”是什么意思了——一个没有说明问题的东西。@Franois:谢谢你的回答……我是在谈论iphone布局中的第二列……谢谢你的回答……我是在谈论iphone布局中的第二列……如果这回答了你的问题,请告诉我!:-)