1
有誰知道我可以如何使用變量CSS選擇器?例如,我希望我的CSS搶表id
屬性這是變量...是這樣的:如何使用變量CSS選擇器
<table id="table_1">
<thead>
</thead>
<tbody>
</tbody>
</table>
<table id="table_2">
<thead>
</thead>
<tbody>
</tbody>
</table>
<table id="table_3">
<thead>
</thead>
<tbody>
</tbody>
</table>
現在我想通過自己的id
搶表:
table#[INSERT VARIABLE TABLE ID HERE]{
margin: 0 auto;
border-collapse: collapse;
font-family: Agenda-Light, sans-serif;
font-weight: 100;
background: #333; color: #fff;
text-rendering: optimizeLegibility;
border-radius: 5px;
}
提前感謝!
檢查了這個http://stackoverflow.com/questions/12155833/css-selector-id-contains-part-of-text – Sankara
對於這個具體的例子:'table [id^= table_]'將選擇所有'
不,這是不可能的,CSS沒有變量。您需要將其作爲一個類,然後使用JavaScript更改哪個表具有該類。 –
回答
如果所有的表都有相同的CSS,你可以使用類而不是id。
在css中不可能迭代或執行其他類型的邏輯。要使用變量,您可以使用像sass或更少的css預處理器,但是您必須「手動」定義每個變量。
來源
2017-04-01 00:16:42 Ben
相關問題