[英]How to exclusively style parent or child when hovering over either of them?
如果您只打算支持支持:has
的現代常青瀏覽器,那么您可以根據以下條件#parent
樣式:
這轉化為這樣的選擇器: #parent:hover:not(:has(#child:hover))
。
在下面的示例中, #parent
僅在懸停時才顯示為紅色,而不是其子項:
#parent:hover:not(:has(#child:hover)) { background: red; } #child:hover { background: green; }
<div id="parent"> <a href='#link' id="child">Child</a> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.