W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
nth表達(dá)式的形式在擴(kuò)展中很重要,否則它將選擇器視為不同。 nth表達(dá)式1n + 2和n + 2是等效的,但擴(kuò)展將該表達(dá)式視為不同。
例如,使用以下代碼創(chuàng)建一個(gè)LESS文件:
:nth-child(n+2) { color: #BF70A5; font-style: italic; } .child:extend(:nth-child(1n+2)){}
當(dāng)我們在命令提示符中編譯上面的代碼時(shí),你會(huì)得到一個(gè)錯(cuò)誤消息,如下所示。
:nth-child(n+2) { color: #BF70A5; font-style: italic; }
在屬性選擇器中,引用類型不重要,您可以在以下示例中看到它:
下面的例子演示了在LESS文件中使用nth表達(dá)式:
<!doctype html> <head> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <div class="style"> <h2>Hello!!!!!</h2> </div> <p class="img">Welcome to W3Cschool</p> </body> </html>
接下來,創(chuàng)建文件 style.less
[title=tutorialspoint] { font-style: italic; } [title='tutorialspoint'] { font-style: italic; } [title="tutorialspoint"] { font-style: italic; } .style:extend([title=tutorialspoint]) {} .container:extend([title='tutorialspoint']) {} .img:extend([title="tutorialspoint"]) {}
您可以使用以下命令將 style.less 文件編譯為 style.css :
lessc style.less style.css
接下來執(zhí)行上面的命令,它將用下面的代碼自動(dòng)創(chuàng)建 style.css 文件:
[title=tutorialspoint], .style, .container, .img { font-style: italic; } [title='tutorialspoint'], .style, .container, .img { font-style: italic; } [title="tutorialspoint"], .style, .container, .img { font-style: italic; }
讓我們執(zhí)行以下步驟,看看上面的代碼如何工作:
將上述html代碼保存在 extend_syntax.htm 文件中。
在瀏覽器中打開此HTML文件,將顯示如下輸出。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: