W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
您可以使用&字符選擇父級選擇器。 它告訴父選擇器應(yīng)該插入的位置。
下面的示例描述了在SCSS文件中使用父選擇器:
<html> <head> <title>Referencing Parent Selectors</title> <link rel="stylesheet" type="text/css" href="style.css" /> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <script src="/attachments/tuploads/sass/jquery.min.js"></script> <script src="/attachments/tuploads/sass/bootstrap.min.js"></script> </head> <body> <div class="container"> <h1>Example using Parent Selector</h1> <a href="//www.o2fo.com/"> www.o2fo.com </a> </div> </body> </html>
接下來,創(chuàng)建文件 style.scss 。 注意使用&amp; 字符,指定應(yīng)當插入父選擇器的位置。
a { font-size: 20px; &:hover { background-color: yellow; } }
您可以通過使用以下命令讓SASS查看文件并在SASS文件更改時更新CSS:
sass --watch C:\ruby\lib\sass\style.scss:style.css
接下來執(zhí)行上面的命令,它將用下面的代碼自動創(chuàng)建 style.css 文件:
a { font-size: 20px; } a:hover { background-color: yellow; }
讓我們執(zhí)行以下步驟,看看上面的代碼如何工作:
將上述html代碼保存在 parent_selectors.html 文件中。
在瀏覽器中打開此HTML文件,將顯示如下輸出。
此處&amp; 將替換為父選擇器 a 。 當您將鼠標懸停在鏈接上時,它會將背景顏色顯示為黃色。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: