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).
I am looking to do the opposite: preventing an element from having the :hover state applied even though the cursor is over it.
That way I could use the element picker on elements that disappear on hover.
Disable styles individually while :hover is in pinned state
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.
With the element selected, click the "Toggle Element State" pin icon at the top of the styles panel.
Pin the :hover state. See that the selector and rules that define the :hover state now appear.
Disable individual rules as needed to achieve your goal.
Unpin the :hover state.
You have now disabled some or all of the rules applied to your element's :hover state. 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 element
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.
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.
A text input will appear. Enter pointer-events: none;.
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.
Caveat: Because hover events are suppressed, the closest you'll be able to get with the element picker is the target element's parent.
Related
I've grid with several boxes in (<div>). Each box has inside a list with couple/ several links (simple ul li list with <a> elements). This link list is hidden, it shows only on hover.
It works really fine, but I have accessibility issue, namely, I can't get into any list element with "tab" key (box <div> works ok, it get focus, so the list is showing up), it is just skipping to next box element. I've tried with adding tabindex on each box and each list element inside, but it seems that this is not the solution.
Is there any CSS/ HTML solution for that? I can of course write simple JS, that will check where is focus and if focus has parent with focus option, but I would like to avoid it if possible.
How did you hide the link list? Using display: none or using visibility: hidden. (And that you apply this only to the list elements or also to the div? From your description, I guess it applies only to the list elements.) Content that is hidden using display: none is not keyboard accessible.
In order to make the list appear on hover, are you using a JavaScript event handler or CSS? If you are using JavaScript, you probably need to add an event listener that responds to keyboard events (e.g. onfocus, but as mentioned above, content hidden with display: none won't receive focus). In CSS, I always recommend adding the :focus pseudo-class whenever :hover is used (unless you want different styles for these things).
You may need to write some JavaScript that toggles the visibility of the lists when a parent div receives focus. (If you have tabindex on the div elements, as you say, they should already be able to receive focus.)
I have a page that uses jQuery UI for tabs, and I noticed some weird behavior in the Chrome inspector. Here's a screenshot showing the hierarchy up to the element in question, and the CSS rule that is being applied to it.
The CSS rule should apply to elements with class ui-widget-overlay, but the selected element does not have that class. Furthermore, toggling the background and opacity properties in that rule off and back on actually changes the page (when it obviously shouldn't). Is it some weird inspector bug or am I missing something here? It seems that it erroneously displays the rule that is completely irrelevant to the selected element, and toggling the properties makes them apply to the element when they previously weren't.
Since some time, when I inspect an input in Chrome, I see those strange #document-fragment greyed-out elements. I also notice that sometimes there are more, and sometimes there are less of them.
What are these things? And is there a way to hide them in the inspector?
You see this in your inspector because you have the option activated to "Show Shadow DOM".
You find this setting in the general settings tab under the "Elements"
If you deactivate it. These fragments will disappear from your inspector
Shadow DOM is internal to the element and hidden from the end-user. Its nodes are not children of <my-custom-element> or <input> or ... (http://www.polymer-project.org/platform/shadow-dom.html#shadow-dom-subtrees)
You will find more information here:
Inspector: https://developers.google.com/chrome-developer-tools/docs/settings?hl=en
Shadow Dom: http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom/
W3: http://www.w3.org/TR/shadow-dom/#shadow-trees
I have an <img> element within a <div> element. I want the entire div (including the image) to scale down 10% (using transform) whenever the <div> is being clicked on. I have gotten it to work, but with one small issue: if the user clicks the image inside the div, nothing happens, whereas if the user clicks the background of the div, it works.
Essentially, how can I get the :active selector of .MyDiv:hover:active { /*scaling logic here*/ } to also work when children of MyDiv are clicked.
All help is greatly appreciated and I always accept an answer!
The :active pseudo-class and the div element
First things first, I'm pretty sure in a div element shouldn't have an activation state in the first place.
If we read through the user action pseudo-classes :hover, :active, and :focus section of the Selectors Level 3 W3C Recommendation, we find this:
The :active pseudo-class applies while an element is being activated by the user. For example, between the times the user presses the mouse button and releases it. On systems with more than one mouse button, :active applies only to the primary or primary activation button (typically the "left" mouse button), and any aliases thereof.
Now if we head over to the Interactive Content section of the HTML5 W3C Editor's Draft, we find this:
Certain elements in HTML have an activation behavior, which means that the user can activate them.
The user agent should allow the user to manually trigger elements that have an activation behavior, for instance using keyboard or voice input, or through mouse clicks. When the user triggers an element with a defined activation behavior in a manner other than clicking it, the default action of the interaction event must be to run synthetic click activation steps on the element.
I mention the HTML5 Editor's Draft over the HTML401 Recommendation as the HTML401 document doesn't go into great detail about activation states or user interaction. It does however mention activation on elements like the a element, but doesn't mention anything about it when defining the div element.
The div element doesn't have an "activation state" defined in the HTML5 recommendation. It has no Interactive Content category (unlike the a element) and doesn't state that an active state can be applied to it.
A Workaround
As discussed above, the div element shouldn't accept an :active state. For this reason I'm going to modify the HTML to use an element which does. For this, I'm using the a element:
<a href="javascript: void(0)">
<img />
</a>
Now this alone doesn't fix the IE issue. If you see this JSFiddle example, when clicking on the img element the a container isn't given an active state. So what can we do to fix this? Instead of just using :hover:active, I'm also going to use :hover:focus:
a:hover:active,
a:hover:focus {
outline: 0; /* Reset the default anchor tag focus style. */
background: #f00;
}
This gives us similar functionality on IE and all other browsers, as can be seen in this JSFiddle demo.
Two (potentially undesirable) side effects
The problem with this approach is that the element will retain its focussed state and you can now achieve this effect by accessing the element using your keyboard's tab key. Whenever you hover over the element in its focussed state, its style will change. It's not up to me to decide whether this is an undesirable side effect, however.
Your element is now a link. The href property is required in order for the element to be focussed in the first place.
Extra styling
As we're now using an a element instead of a div element, so we'll need to reset any browser default styles which distinguish your element as a link. For this we can simply:
a {
color: #000; /* Reset the color to black. */
cursor: default; /* Reset the cursor to default. */
text-decoration: none; /* Remove the underline. */
}
a img {
border: none; /* Remove border from image. */
}
Final JSFiddle demo.
I want to inspect CSS style of a list, applied by ul li:hover > ul {} rule in Firebug.
So the trick with checkbox on ":hover" won't work, cause I have to hover the inspected element's parent, not the element itself.
How do I inspect style applied to that kind of element? Is there any way I could move to the style panel with a hotkey, while holding the mouse over element's parent? Thanks in advance.
The best thing I managed to do is painfully and patiently Tab the focus to Style subwindow. It worked, but I wish there was a better way to do that.
I just released a tool that you can use to easily view the layout of all of your elements - even in their hover state.
HTML Box Visualizer - GitHub