热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

是:悬停仅限于子元素?-Is:hoveronlylimitedtochildelements?

Ijustsawthiscodeinananswer:我刚刚在答案中看到了这段代码:HTMLHTML<div><

I just saw this code in an answer:

我刚刚在答案中看到了这段代码:

HTML

HTML

CSS

CSS

.overthumb { display: none; }

.thumbnail:hover .overthumb {
    position: absolute;
    top: 15px; left: 15px;
    display: inline;
}

Live demo here: http://jsfiddle.net/6wQp3/

现场演示:http://jsfiddle.net/6wQp3/

For this code to work .overthumb must be a child of .thumbnail.

要使此代码有效,.overthumb必须是.thumbnail的子代。

But if some one has this code:

但如果有人有这个代码:

tttttttttt

How would you select the p tag if .thumbnail is hovered?

如果.thumbnail悬停,你会如何选择p标签?

2 个解决方案

#1


10  

Live Demo

现场演示

You can use the adjacent sibling selector

您可以使用相邻的兄弟选择器

.thumbnail:hover + p {
    background:yellow;
}

#2


5  

You can use the following selector

您可以使用以下选择器

.thumbnail:hover + p 

Example: http://jsfiddle.net/6wQp3/2/

示例:http://jsfiddle.net/6wQp3/2/


推荐阅读
author-avatar
敬昇文军3546
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有