文章詳情頁
css - :nth-child(n)選擇器中的n可不可以引用到屬性中?
瀏覽:102日期:2023-08-03 09:22:59
問題描述
如果是原生的CSS(不使用編譯器)可不可以達(dá)到這樣的效果?或者有沒有哪個屬性或方法是可以使數(shù)值與n相關(guān)的?
.box:nth-child(n){ -webkit-animation-delay:n s; animation-delay:n s;}
問題解答
回答1:在原生的基礎(chǔ)上,部分 Firefox 瀏覽器可以實(shí)現(xiàn) CSS 變量
element { --animation-delay: 3s;} .box:nth-child(n) {-webkit-animation-delay: var(--animation-delay);animation-delay: var(--animation-delay);}
詳情看 MDN 的文檔 https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables
回答2:不行nth-child(n) 中的n可以是an+b形式,或odd,even或數(shù)字,所以不應(yīng)該被作為變量使用你要實(shí)現(xiàn)的效果應(yīng)該用js實(shí)現(xiàn)或者可以使用一些支持變量的css預(yù)處理語言
標(biāo)簽:
CSS
相關(guān)文章:
1. 為什么我ping不通我的docker容器呢???2. 關(guān)于docker下的nginx壓力測試3. javascript - vue vue-router 報(bào)$router重復(fù)定義4. java - 根據(jù)月份查詢多個表里的內(nèi)容怎么實(shí)現(xiàn)好?5. javascript - webpack熱加載配置不生效6. 關(guān)于Java引用傳遞的一個困惑?7. debian - docker依賴的aufs-tools源碼哪里可以找到啊?8. windows2003下的apache響應(yīng)時間特別長?9. angular.js - angular內(nèi)容過長展開收起效果10. node.js - node exec 執(zhí)行沒反應(yīng)
排行榜

熱門標(biāo)簽