其它常用选择器随记(伪类选择器)

it2026-09-01  1

1.p::first-letter :选中p中的首个字母 2.p::first-line :选择p中的第一行

<html> <head> <title>小朋友</title> <style> p:first-letter{ /*首个字母 */ font-size:xx-large; /*首个字母字体放大*/ background-color:tomato; } P:first-line{ /*选择p中的第一行*/ color: violet; font-weight:bold; } </style> </head> <body> <p>Hello,nice to meet you! Nothing's gonna change my love for you if i had to live my  life without you near me   i don't want to live without you   Waiting for my favorite songs   When they played I'd sing along it made me smile    Those were such happy times and not so long ago   How I wonder where they'd gone    But they're back again just like a long lost friend   All the songs I love so well    Every sha la la la …… every wo wo ……</p> <div> </div> </body> </html>

3.p:first-child :选择第一个p 4.p:last-child :最后一个p 5.p:nth-child(2) :随意在括号里选择第几个p

小朋友 </head> <body> <p>Hello1</p> <p>Hello2</p> <p>Hello3</p> <p>Hello4</p> </body>
最新回复(0)