![](/img/trans.png)
[英]Combine multiple selectors with the same attribute selector into one selector in CSS
[英]how to combine the Universal selector and Attribute selectors in CSS
我需要滿足這個需求:編寫您的頁面,以便將鼠標懸停在任何元素(即任何標題,段落,圖像等)上時,該元素都會以黃色突出顯示。這必須是單選,單屬性的您的樣式表-不允許使用逗號! (注意:這很棘手。)
作為需求,這很棘手! 希望你能幫我,THX〜
我用過z-index
和pseudo
元素:after
這是js小提琴
* { position:Relative; background: transparent; z-index:1; } *:hover:not(html):not(body):after { content:" "; background: yellow; display:block; position:absolute; top:0; bottom:0; right:0; left:0; z-index:-1; }
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p> <div>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</div> <h1><p>Lorem ipsum dolor</p></h1>
您可以為此使用jQuery
$(document).ready(function(e){
$('*').mouseenter(function(){
$(this).css('background','yellow');
}).mouseleave(function(){
$(this).css('background','#fff')
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.