css3 - css 選擇器如何同時使用屬性選擇和順序選擇?
問題描述
我需要給 p[class^='xxx'] 的最后一個元素定義樣式,可是寫 p[class^='xxx']:last-of-type 不起作用,請問要怎么寫呢?
問題解答
回答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的區別
相關文章:
1. javascript - 關于apply()與call()的問題2. 安全性測試 - nodejs中如何防mySQL注入3. java - spring boot 如何打包成asp.net core 那種獨立應用?4. java - 在用戶不登錄的情況下,用戶如何添加保存到購物車?5. javascript - nginx反向代理靜態資源403錯誤?6. docker網絡端口映射,沒有方便點的操作方法么?7. docker - 各位電腦上有多少個容器啊?容器一多,自己都搞混了,咋辦呢?8. MySQL 查詢疑問?9. 推薦好用mysql管理工具?for mac和pc10. javascript - 如何將函數計算出的內容傳遞為變量
