Hide div when input on Focus, css

Asked

Viewed 508 times

3

How can I hide my div when the input is in Focus? I used this Cod and it didn’t work for me

.A:focus  .B {
    display: inline-block !important;
}
  • with css only this will not be possible, you will insert an onfocus into the input which is a javascript type pointing to a function and in this function you will create a css element for the div you want

1 answer

2


You can do something like this:

div {
     background: #f0a;
     display: true;
     height: 200px;
     width: 200px; }

input:focus + div { display: none }

DEMO

You can use classes or identifiers like this:

div.hidden {
background: #f0a;
display: true;
height: 200px;
width: 200px; }
input.focus:focus + div.hidden { display: none }

And then add the HTML like this:

<input class="focus" type="text" value="">
<div class="hidden"></div>

DEMO

  • wow, I’ve never seen this method, really good anyway, I used onFocus="eventtipsignupnomefocus()" onBlur="eventtipsignupnomeblur()", this is very Manero

  • @flourigh css is amazing when you know how to use it..

  • @user3715916 because it’s a boy, I never tried to use it, because I’ve always made it with Javascript so I’ve never looked, but now I love this method that even works in many ways, very good, this is from CSS3? correct

  • @flourigh CSS2.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.