css - 当其容器/父元素悬停时将css样式应用于元素
问题描述
当我将鼠标悬停在元素的容器上时,我希望元素接收 css/scss 的视觉变化。
要求: - 需要在子组件或 sass 文件中发生。无法了解父子关系。- sass css 或在角度组件内
我已经尝试过有角度的主机侦听器装饰器,但这只是主机元素而不是它的父元素。
我尝试过 :host 和 :host-context 选择器,但与主机侦听器有类似的经验。
任何建议将不胜感激。
编辑:为了形象化,我可以在一个大方形元素内有一个小方形元素,然后当小方形元素与大方形元素的区域不重叠的空间悬停时,小方形接收一个样式。
澄清:
解决方案
In the HTML of the small square, wrap it with a div:
<div class="small-square">
// rest of HTML
</div>
In the CSS of small square:
.small-square:hover {
// styles
}
Why can't you do this? Sorry if I don't fully understand the question.
UPDATE:
You could do this in your global stylesheet (AKA styles.css):
.large-square:hover .small-square {
// styles for small square when large square is hovered
}
UPDATE 2:
Not sure if host context would support use of :hover as follows:
:host-context(.large-square:hover) .small-square {
// styles for small square when large square is hovered
}
:host-context(*:hover) .small-square {
// styles for small square when large square is hovered
}
If it doesn't then I think you have no choice but to use global stylesheet.
推荐阅读
- c# - 连续相同的字符列表,我无法全部删除
- docker - docker-compose 使用 dockerfiles 运行 2 个服务,找不到任务“phx.server”,main.go:没有这样的文件或目录
- vb.net - VB.NET TCP 服务器/客户端 - 获取连接客户端的 IP
- wso2 - 如何执行 WSO2 用户身份验证
- assembly - 如何在蓝屏上打印文本?
- javascript - addEventListener("touchstart") 在手机上不起作用
- powershell - 无法执行 Import-Module Azure PowerShell 命令
- php - 如何用两列编写 Laravel Eloquent whereBetween 方法
- javascript - 特定锚标签的平滑滚动不适用于所有锚标签
- javascript - 递归模式js