0
<div id='searchParent'>
    <!--icon to be hovered-->
    <i id="search" class="fas fa-search"></i>
    <!--icon to be hovered-->
        <div id="inputParent">
            <!--input to be shown-->
            <input type="text" placeholder='Pesquise' autocomplete='off' id="input-bar">
            <!--input to be shown-->
        </div>
</div>

I´ve been working in this for a really long time, and the best piece of css hover i could get was this:

#search:hover ~ #inputParent #input-bar {
    width: 200px;
}

But the problem is that when you hover the input it just drag it way out and you cant just write anything. The icons are in my local machine but i will prolably put them in there

EDIT: I´m going to show some of my poor css and what i was intending to do.

input {
  border: none;
  outline: none;
  border-bottom: 0.3px solid black;
}

#search {
  padding-left: 180px;
  display: inline-block;
}

#inputParent {
    margin-left: auto;
}

#input-bar {
    margin-right: 1vw;
    width: 0;
    transition: 0.8s ease-in-out;
} 


#search:hover ~ #inputParent #input-bar {
    width: 200px;
}
<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
  </head>
  
  <body>
    <div id="searchParent">
        <i id="search" class="fas fa-search"></i>
        <div id="inputParent">
            <input type="text" placeholder="Pesquise" autocoplete="off"       id="input-bar">
        </div>
    </div>
  </body>
</html>

What i really wanted to do was to when i hovered the input it stay there. I really dont know why the bar is going from the left to the right, it was suposed to go backwards

Vitor Gouveia
  • 53
  • 2
  • 9
  • Hi and welcome to SO! I think we will need more code (especially css) to see your problem. Do you know that you can insert runnable html/js/css snippets directly to your question? – lupz May 20 '20 at 07:36
  • Hover would be the wrong method here since when you move the mouse to the input you stop hovering the icon and the input will disappear. I'd find another method. – Paulie_D May 20 '20 at 07:38
  • @Paulie_D this is quite easy if he adds a div class around his icon and input section. See my answer. – John May 20 '20 at 07:57
  • @John I'm aware ...changing the HTML would be one of the "other methods" I mentioned but I don't know if the OP can do that. – Paulie_D May 20 '20 at 07:58

1 Answers1

0

Hi If you are able to add a new div to your HTML and add a class to your inputParent this is quite easy. Please see my code:

.dropdown {
  position: relative;
  display: inline-block;
}

#inputParent {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  padding: 12px 16px;
  z-index: 1;
}

.dropdown:hover #inputParent {
  display: block;
}
<div id='searchParent'> 
    <!--icon to be hovered-->
    <div class="dropdown">
    <i id="search" class="fas fa-search"></i>Icon
    <!--icon to be hovered-->
        <div id="inputParent" class="parentc">
            <!--input to be shown-->
            <input type="text" placeholder='Pesquise' autocomplete='off' id="input-bar">
            <!--input to be shown-->
        </div>
         </div>
</div>
John
  • 5,132
  • 1
  • 6
  • 17