CSS3 知识量:11 - 43 - 138
否定伪类选择器用来定位不匹配该选择器的元素。
否定伪类选择器的语法很简单,形如:
E:not(F)
表示匹配所有除元素F以外的E元素。
下面是一个否定伪类选择器的示例,功能是选择除第3段文字外的内容,并将字体设置为蓝色加粗显示。
<!DOCTYPE html> <html> <head> <title>否定伪类选择器</title> <meta charset="UTF-8"> <style type="text/css"> div p:not(:nth-child(3)){ color: blue; font-weight: 900; } </style> </head> <body> <h2>The Three Little Pigs</h2> <div> <p>Once upon a time there were three little pigs and the time came for them to leave home and seek their fortunes.</p> <p>Before they left, their mother told them " Whatever you do , do it the best that you can because that's the way to get along in the world.</p> <p>The first little pig built his house out of straw because it was the easiest thing to do.</p> <p>The second little pig built his house out of sticks. This was a little bit stronger than a straw house.</p> <p>The third little pig built his house out of bricks.</p> </div> </body> </html>
显示的效果为:
Copyright © 2017-Now pnotes.cn. All Rights Reserved.
编程学习笔记 保留所有权利
MARK:3.0.0.20240214.P35
From 2017.2.6