首页 > Web开发 > 详细

CSS邻接选择器

时间:2015-07-20 16:49:35      阅读:369      评论:0      收藏:0      [点我收藏+]

div + p{

  ...

}

选中与div‘相邻‘的p


这个相邻为什么打引号?

<!DOCTYPE html>
<html>
<head>
<style>
div + p {
    background-color: yellow;
}
</style>
</head>
<body>
<p>Paragraph 0. Not in a div.</p>
<div>
<p>Paragraph 1 in the div.</p>
<p>Paragraph 2 in the div.</p>
</div>
<p>Paragraph 3. Not in a div.</p>
<p>Paragraph 4. Not in a div.</p>
</body>
</html>

哪些p会是补选中的呢?


只有 3 是被选中的,如果出乎意料,说明你这个‘相邻‘没有搞清楚


那么0 为什么没有呢?它也是div的相邻元素


原来 ‘+‘ 这个所谓的相邻只是‘紧随其后的相邻‘


相邻2

div ~ p{

 ...

}

<!DOCTYPE html>
<html>
<head>
<style>
div ~ p {
    background-color: yellow;
}
</style>
</head>
<body>
<p>Paragraph 0. Not in a div.</p>
<div>
<p>Paragraph 1 in the div.</p>
<p>Paragraph 2 in the div.</p>
</div>
<p>Paragraph 3. Not in a div.</p>
<p>Paragraph 4. Not in a div.</p>
</body>
</html>

3 ,4 会被选中..此处‘相邻‘为:‘其后的相邻‘



本文出自 “web之路” 博客,请务必保留此出处http://liuzhongcool.blog.51cto.com/10509488/1676353

CSS邻接选择器

原文:http://liuzhongcool.blog.51cto.com/10509488/1676353

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!