css3 - css 選擇器如何同時(shí)使用屬性選擇和順序選擇?
問題描述
我需要給 p[class^='xxx'] 的最后一個(gè)元素定義樣式,可是寫 p[class^='xxx']:last-of-type 不起作用,請(qǐng)問要怎么寫呢?
問題解答
回答1:<!DOCTYPE html><html> <head><meta charset='UTF-8'><title></title> </head> <style type='text/css'>.d1{ width: 200px; height: 500px; background-color: #0077B0;} </style> <body><p class='d1'> <ul><li class='zz'>li-1</li><li class='zz'>li-2</li><li class='zz'>li-3</li><li class='zz'>li-4</li><li class='zz'>li-5</li> </ul></p><script src='http://libs.baidu.com/jquery/2.0.0/jquery.min.js'></script><script type='text/javascript'> $(function() {$('.d1').click(function() { alert( $('li.zz:last').text() );}) })</script> </body></html>
last last-child 都可以
你很可能需要了解一下last-of-type和last-child的區(qū)別
相關(guān)文章:
1. 如何解決docker宿主機(jī)無(wú)法訪問容器中的服務(wù)?2. angular.js - $stateChangeSuccess事件在狀態(tài)跳轉(zhuǎn)的時(shí)候不執(zhí)行?3. mysql 一個(gè)sql 返回多個(gè)總數(shù)4. angular.js - ionic2 瀏覽器跨域問題5. javascript - 螞蟻金服里的react Modal方法,是怎么把元素插入到頁(yè)面最后的6. 如何用筆記本上的apache做微信開發(fā)的服務(wù)器7. android - rxjava merge 返回Object對(duì)象數(shù)據(jù)如何緩存8. CSS3 畫如下圖形9. python - Scrapy存在內(nèi)存泄漏的問題。10. java如何生成token?
