0
<div class="row">
    <span class="show-on-hover"><button>Remove</button></span>
    <span class="hide-on-hover">1.00</span>
    <span class="show-on-hover"><input value="1.00"></span>
</div>

I want a CSS solution to show the input when the div is hovered over OR when the input has focus. I've figured out the hover:

div.row .show-on-hover{ display:none; }
div.row:hover .hide-on-hover{ display:none; }
div.row:hover .show-on-hover{ display:inline; }

But how do I keep the above rules if the input has focus as well (including the remove span as well)?

Bradley
  • 2,071
  • 2
  • 21
  • 32
  • 1
    There is also a [`:focus`](https://developer.mozilla.org/en-US/docs/Web/CSS/:focus) pseudo class. – ajp15243 Feb 26 '14 at 20:53
  • Are you asking: if you hover the row which exposes the input, then focus the input, then mouse away, you want the input to still be visible? – skyline3000 Feb 26 '14 at 20:59
  • @skyline3000: exactly, yes. – Bradley Feb 26 '14 at 21:00
  • @ajp15243 Did you try your suggestion before pointing out the obvious? No. Regardless of whether you use one or a combination of the display, visibility, or opacity properties, the :focus pseudo-class will have no effect on elements that are initially hidden. – Michel Joanisse Oct 24 '16 at 16:56

3 Answers3

1

Now i've played around with your problem and it seems like there is no solution to your specific issue without using some kind of script to control the show/noshow.

Here's what I got:

CSS

div:hover input {display:inline;}
input:focus {display:inline;}
input {display:none;}

HTML

<div> 
    <!-- <input id="same" type="button" value="Remove" /> -->
    <span class="hide-on-hover">1.00</span>
    <input id="same" value="1.00">
</div>

Result: http://jsfiddle.net/2thMQ/2/

Anonymous
  • 1,303
  • 4
  • 19
  • 31
1

Use the focus-within selector of the div element. The focus within applies style to the div/row if any element inside the div/row is focused.

div.row .show-on-hover {
  display: none;
}
div.row:hover .hide-on-hover,
div.row:focus-within .hide-on-hover {
  display: none;
}
div.row:hover .show-on-hover,
div.row:focus-within .show-on-hover {
  display: inline;
}
swift-lynx
  • 3,219
  • 3
  • 26
  • 45
0

i think you are looking for something like this:

div.row .show-on-hover{ display:none; }
div.row:active .hide-on-hover{ display:none; }
div.row:active .show-on-hover{ display:inline; }
samuel.molinski
  • 1,119
  • 10
  • 24