input:checked + label;input:checked ~ label分别是什么意思

input:checked + label 

input:checked ~ label

input:checked ~ label   :相邻同胞选择器,选择被勾选的input标签后 所有的label标签[input  和 label标签有共同的父元素];

input:checked + label   :相邻同胞选择器,选择被勾选的input标签后 第一个label标签[input  和 label标签有共同的父元素];

//-------------------------------------------------------------------------------示例

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
 
 
 
#checked_1:checked+label{
    background-color:red;
}

.checked_class:checked~label{
    background-color:red;
}

 
</style>
</head>

<body>

<div >
  <input id="checked_1" type="checkbox"  />
  <label for="checked_1">aaaa</label>
  <label for="checked_1">bbbb</label>
</div> 

<div >
  <input id="checked_2" class="checked_class" type="checkbox"  />
  <label for="checked_2">aaaa</label>
  <label for="checked_2">bbbb</label>
</div> 

 
</body>
</html>

猜你喜欢

转载自blog.csdn.net/ozhy111/article/details/84329093