您的位置:首頁技術文章
文章詳情頁

css - :nth-child(n)選擇器中的n可不可以引用到屬性中?

瀏覽:83日期:2023-08-03 09:22:59

問題描述

如果是原生的CSS(不使用編譯器)可不可以達到這樣的效果?或者有沒有哪個屬性或方法是可以使數值與n相關的?

.box:nth-child(n){ -webkit-animation-delay:n s; animation-delay:n s;}

問題解答

回答1:

在原生的基礎上,部分 Firefox 瀏覽器可以實現 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或數字,所以不應該被作為變量使用你要實現的效果應該用js實現或者可以使用一些支持變量的css預處理語言

標簽: CSS
相關文章:
国产综合久久一区二区三区