How do I open a floating div style tooltip when clicking an input?

3

Hello.

I have a problem that I can not resolve. I have an input of type text and needed that when I clicked it open a window or floating div underneath it like a tooltip but with HTML inside it.

How can I make when I click on a <input> to display a floating div as a tooltip under <input> ? So:

Ineedtomakeitlooklikethisimage.ItriedwithatooltipbutitdidnotworkbecauseitdisappearswhenIhoverthemouseoverit.Ithoughtaboutusingadiv.

<divclass="info-input-style">
    <input type="text" name="grupos" id="grupos">
    <div id="conteudo">
        <p>HTML DENTRO DA DIV #CONTEUDO </p>
    </div>
<div>

But I have no idea how to do this. Can anyone help me?

    
asked by anonymous 07.09.2017 / 14:51

3 answers

3

You can make the%% float appear when you click <div> in many ways.

I introduce one using JQuery.

Note: I chose to format the HTML and CSS to look similar to the one presented in the image, and for that reason it was still a bit long.

>

   
$("#grupos").click(function(){
  $("#conteudo").show(); //quando clica no input mostra o conteudo
});

$("body, #aplicar").click(function(){
  $("#conteudo").hide(); //quando aplica ou clica fora esconde
});

//este é preciso também para não esconder quando clica no grupos ou conteudo
$("#grupos, #conteudo").click(function(e){
  e.stopPropagation(); 
});
#conteudo {
  margin-top:17px;
  padding:0px 20px;
  box-shadow:0px 0px 3px #777;
  width:250px;
  color:gray;
  display:none;
  position:relative;
}

#conteudo h1 {
  font-size:20px;
  margin:0;
}

#conteudo input {
  width:180px;
}

#conteudo:before { /*a seta do div flutuante*/
  content: "";
  position: absolute;
  top: -10px;
  left: 135px;
  height: 20px;
  width: 20px;
  background-color: white;
  transform: rotate(45deg);
  box-shadow: -2px -2px 1px #ccc;
}

#aplicar {
  text-decoration:none;
  color:#2dabb9;
  font-size:15px;
  position:absolute;
  right:5px;
  bottom:5px;
}

.bloco {
  padding:20px 0px;
  position:relative;
}

.bloco:not(:last-child) {
  border-bottom:1px solid #ccc;
}

label {
  display:block;
  color:#5f5f5f;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divclass="info-input-style">
    <label>Label</label>
    <input type="text" name="grupos" id="grupos">
    <div id="conteudo">
        <div class="bloco">
          <h1>Titulo 1</h1>
        </div>
        <div class="bloco">
          <input type="text" placeholder="Insira a sua cidade de destino">
        </div>
        <div class="bloco">
          <a href="#" id="aplicar">Aplicar</a>
        </div>
    </div>
<div>
    
21.09.2017 / 02:27
0

In the script, you can switch to other hover events, etc ...

Css:

.popover {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1060;
  display: none;
  max-width: 276px;
  padding: 1px;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  font-style: normal;
  font-weight: normal;
  line-height: 1.42857143;
  text-align: left;
  text-align: start;
  text-decoration: none;
  text-shadow: none;
  text-transform: none;
  letter-spacing: normal;
  word-break: normal;
  word-spacing: normal;
  word-wrap: normal;
  white-space: normal;
  background-color: #fff;
  -webkit-background-clip: padding-box;
          background-clip: padding-box;
  border: 1px solid #ccc;
  border: 1px solid rgba(0, 0, 0, .2);
  border-radius: 6px;
  -webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, .2);
          box-shadow: 0 5px 10px rgba(0, 0, 0, .2);

  line-break: auto;
}

.popover.bottom {
  margin-top: 10px;
}

.popover-title {
  padding: 8px 14px;
  margin: 0;
  font-size: 14px;
  background-color: #f7f7f7;
  border-bottom: 1px solid #ebebeb;
  border-radius: 5px 5px 0 0;
}
.popover-content {
  padding: 9px 14px;
}
.popover > .arrow,
.popover > .arrow:after {
  position: absolute;
  display: block;
  width: 0;
  height: 0;
  border-color: transparent;
  border-style: solid;
}
.popover > .arrow {
  border-width: 11px;
}
.popover > .arrow:after {
  content: "";
  border-width: 10px;
}
.popover.top > .arrow {
  bottom: -11px;
  left: 50%;
  margin-left: -11px;
  border-top-color: #999;
  border-top-color: rgba(0, 0, 0, .25);
  border-bottom-width: 0;
}
.popover.top > .arrow:after {
  bottom: 1px;
  margin-left: -10px;
  content: " ";
  border-top-color: #fff;
  border-bottom-width: 0;
}

.popover.bottom > .arrow {
  top: -11px;
  left: 50%;
  margin-left: -11px;
  border-top-width: 0;
  border-bottom-color: #999;
  border-bottom-color: rgba(0, 0, 0, .25);
}
.popover.bottom > .arrow:after {
  top: 1px;
  margin-left: -10px;
  content: " ";
  border-top-width: 0;
  border-bottom-color: #fff;
}

HTML

   <div class="bgform-2 popover fade bottom in">
     <div class="arrow"></div>
     <h3 class="popover-title">Titulo 1</h3>
    <div class="popover-content">
      <form>
         <fieldset>
         <legend>Form</legend>
         <label>Nome: </label>
             <input type="text" placeholder="digite seu nome completo"/>
             <input type="submit" value="Enviar" /> 
         </fieldset>
      </form>
    </div>
 </div>
<button type="submit" id="btn">
                            Enviar
</button>

Jquery

$("#btn").click(function(){
        $('.popover').toggle(250);
    })

Follow the demo ...

link

    
19.09.2017 / 21:43
0

Getting blown up our document plugins and libraries will only detonate the traffic

A simple Javascript solves the problem. CSS is on your own!

document.onclick=evento; 
function evento(e){ 
var target = (e && e.target) || (event && event.srcElement); 
var obj = document.getElementById('minhadiv'); 
var obj2 = document.getElementById('clica'); 
checkParent(target)?obj.style.display='none':null; 
target==obj2?obj.style.display='block':null; 
} 

function checkParent(t){ 
while(t.parentNode){ 
if(t==document.getElementById('minhadiv')){ 
return false 
} 
t=t.parentNode 
} 
return true 
}
<input id="clica" type="text" value="2">

<div style="display: none;" id="minhadiv">
	
	<h3>Titulo 1</h3>

	<input type="text" name="cidade" placeholder="Insira sua cidade de destino"> 
	<a href="#" id="aplicar">Aplicar</a>
	
</div>
  

If you're not going to make a great framework, or complex system, or a giant site, consider using pure Javascript.

    
07.09.2017 / 19:22