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. Docker for Mac 創建的dnsmasq容器連不上/不工作的問題2. html5 - 為什么有的時候要在網頁中加偽元素3. html - Python2 BeautifulSoup 提取網頁中的表格數據及連接4. python - PyCharm里的一個文件不小心忽略了wx包5. html5 - css 這種六邊形的邊框怎么畫?6. html5 - javascript讀取自定義屬性的值,有的能夠取到,有的取不到怎么回事??7. 小白學python的問題 關于%d和%s的區別8. win10 Apache24+PHP8.0,Apache不能正常加載php.ini。9. javascript - 關于微信掃一掃的技術問題10. html5 - 請問利用font-face定義的字體怎么在canvas里應用?
