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 会被选中..此处'相邻'为:'其后的相邻'
立即学习“前端免费学习笔记(深入)”;
立即学习“前端免费学习笔记(深入)”;
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号