批改状态:合格
老师批语:
<head><style>h1 {background-color: red;}</style></head><body><h1>标签选择器</h1></body>
<head><style>h1[class="ooo"] {background-color: red;}.ooo {background-color: red;}#ooo {background-color: red;}</style></head><body><h1 id="ooo" class="ooo">类选择器</h1></body>
<head><style>/* 1. 后代选择器,所有层级 */ul li{background-color: red;}/* 子元素选择器:仅父子层级 */body>ul>li {background-color: red;}/* 同级相邻选择器:仅选中相邻的第一个兄弟元素 */li+li{background-color: red;}/* 同级所有选择器:选中与之相邻的后面所有的兄弟元素 */li~li{background-color: red;}</style></head><body><ul><li>li-1</li><li>li-2</li><li>li-3</li><li>li-4</li><li>li-5<ul><li>li-1</li><li>li-2</li><li>li-3</li><li>li-4</li></ul></li></ul></body>
<head><style>/* 匹配任意位置元素: :nth-of-type(an+b)偶数:odd奇数:even*/ul li:nth-of-type(0n+3){color : red;}/* 反向获取任意元素: :nth-last-of-type(an+b) */ul li:nth-last-of-type(-n+3){color : red;}/* 选择第一个子元素: :first-of-type选择最后一个子元素: :last-of-type*/ul li:first-of-type{color : red;}ul li:last-of-type{color : red;}/* 匹配父元素的唯一子元素: :only-of-type */ul li:only-of-type{color : red;}</style></head><body><ul><li>li-1</li><li>li-2</li><li>li-3</li><li>li-4</li><li>li-5</li></ul></body>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号