简体   繁体   English

在 Chrome 开发者工具中禁用 :hover 状态

[英]Disable :hover state in Chrome Developer Tools

I am aware you can force the :hover state on an element from the Dev Tools (see eg: See :hover state in Chrome Developer Tools ).我知道您可以从开发工具中强制元素上的:hover状态(参见例如: 参见 Chrome 开发者工具中的 :hover 状态)。

I am looking to do the opposite: preventing an element from having the :hover state applied even though the cursor is over it.我希望做相反的事情:即使光标在元素上,也阻止元素应用:hover状态

That way I could use the element picker on elements that disappear on hover.这样我就可以在悬停时消失的元素上使用元素选择器。

Disable styles individually while :hover is in pinned state:hover处于固定状态时单独禁用样式

  1. Because you want to use the element picker on elements that disappear on hover, you will need to open Chrome Developer tools and manually navigate the DOM tree to the target element node.因为您想在悬停时消失的元素上使用元素选择器,所以您需要打开 Chrome 开发者工具并手动将 DOM 树导航到目标元素节点。
    在此处输入图片说明
  2. With the element selected, click the "Toggle Element State" pin icon at the top of the styles panel.选择元素后,单击样式面板顶部的“切换元素状态”图钉图标。
    在此处输入图片说明
  3. Pin the :hover state.固定:hover状态。 See that the selector and rules that define the :hover state now appear.看到定义:hover状态的选择器和规则现在出现了。
    在此处输入图片说明
  4. Disable individual rules as needed to achieve your goal.根据需要禁用个别规则以实现您的目标。
    在此处输入图片说明
  5. Unpin the :hover state.取消固定:hover状态。
    在此处输入图片说明

You have now disabled some or all of the rules applied to your element's :hover state.您现在已经禁用应用于元素的:hover状态的部分或全部规则。 You can selectively turn these back on by following the steps above and enabling some or all of the rules.您可以通过执行上述步骤并启用部分或全部规则,有选择地重新启用这些功能

Apply pointer-events: none to the target elementpointer-events: none应用于目标元素

  1. Because you want to use the element picker on elements that disappear on hover, you will need to open Chrome Developer tools and manually navigate the DOM tree to the target element node.因为您想在悬停时消失的元素上使用元素选择器,所以您需要打开 Chrome 开发者工具并手动将 DOM 树导航到目标元素节点。
    打开 Chrome 开发者工具并手动将 DOM 树导航到目标元素节点
  2. With the element selected, from the styles panel click somewhere near the closing bracket of the target rule to insert a new property.选择元素后,从样式面板单击目标规则右括号附近的某处以插入新属性。 I recommend using the element.style rule to achieve the greatest specificity.我建议使用element.style规则来实现最大的特异性。
    在此处输入图片说明
  3. A text input will appear.将出现文本输入。 Enter pointer-events: none;输入pointer-events: none; . .
    在此处输入图片说明
    在此处输入图片说明
  4. You may now toggle this property by disabling/enabling it as normal.您现在可以通过正常禁用/启用它来切换此属性。
    在此处输入图片说明

While enabled, this precludes the invocation of any :hover rules applied to the target element.启用后,这会阻止调用任何应用于目标元素的:hover规则。

Caveat: Because hover events are suppressed, the closest you'll be able to get with the element picker is the target element's parent.警告:因为悬停事件被抑制,您可以使用元素选择器获得的最接近的是目标元素的父元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM