Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set element's :hover state in Chrome dev tools and edit child's style

Suppose we have this style:

.parent .child { ... }

.parent:hover .child { ... }

Both selectors set style for child elements.

What I would like is to edit the second style.

  1. I click on .parent and set :hover state in Chrome developer tools
  2. Click on a .child element to get to child's style but...

When I click on .child the hover on parent is gone (because it's now set on .child).

This works in Firebug though but I need it in Chrome...

Chrome 21.0.1180.89 m

like image 733
Robert Koritnik Avatar asked Sep 12 '12 15:09

Robert Koritnik


People also ask

How do I add hover to Chrome developer tools?

To force an element into :hover state, right click it and select :hover . Additional tips on the elements panel in Chrome Developer Tools Shortcuts. Not sure when this changed, but you can now right click -> force element state (from the elements pane) on other elements (not just <a> elements) now.


3 Answers

Update: Chrome now has the following new hotness:

  1. Right-click the child element and choose Inspect Element
    • Chrome will open the Elements view with the item selected
       
  2. In the Elements view, right-click the parent element and choose "Force Element State ▶ :hover"
    Screenshot of "Force Element State" menu

  3. Select the child element in the Elements view again.


Older, valid-but-obnoxious technique follows:

Tested with this JSFiddle:

  1. Hover the child element itself (which also hovers the parent).
  2. Right-click the child.
  3. Using the keyboard (not mouse) move the context menu selection down to "Inspect Element" and press Enter
    • Hurrah, the CSS rule for the hovered parent and selected child is available
  4. Edit the rule. (You may move the mouse to do this; the item will be unhovered, but the CSS rule with the :hover in it will not go away.)
  5. Hover the mouse back over the element to see the changed rule take effect.

Note that if you do it wrong in step 3 (if you use the mouse) you have to select a different element first before trying again.

like image 163
Phrogz Avatar answered Nov 12 '22 04:11

Phrogz


(Chrome 22)

In the Elements panel, right-click the .parent element and select Force Element State > :hover in the context menu. Voila.

Alternatively, you can click the "pointer over a dotted rectangle" button in the Styles pane header at the right and check/uncheck pseudo-classes to be forced on the currently selected element.

Element state can now be forced on any elements in the DOM tree, not only the currently selected one.

like image 29
Alexander Pavlov Avatar answered Nov 12 '22 02:11

Alexander Pavlov


When you have the dev tools open and your looking at the style pane on the right side of the header bar where it says Styles, there is a plus button where you can add custom inspector-stylesheet rules. This may be what your looking for.

like image 33
Ryan Avatar answered Nov 12 '22 04:11

Ryan