Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
I want "divs" of second row to be arranged right below first row of "divs" but they getting arranged leaving a gap

CSS: After clicking the button, you will see the divs getting created in line. I want "divs" of second row to be arranged right below first row of "divs" but they getting arranged leaving a gap. The text alignments inside the "divs" shouldn't get disturbed.

function myFunction() {
  addWordToList("Apple", "Fruit");
}

    var spno = 0;

    function addWordToList(Word, Meaning)
    {
      spno++;
      var dv = document.createElement("DIV");
      document.body.appendChild(dv);
      dv.setAttribute("class", "tooltip");
      dv.setAttribute("id", "pilldiv"+spno);
      document.getElementById("pilldiv"+spno).textContent=Word;
      dv.insertAdjacentHTML('afterend', " ");
      var spn = document.createElement("SPAN");
      dv.appendChild(spn);
      spn.setAttribute("class", "tooltiptext");
      spn.setAttribute("id", "spn"+spno);
      document.getElementById("spn"+spno).textContent=Meaning;
    }
.tooltip {
  position: relative;
  display: inline-block;
  width: auto;
  height: 1.6em;
  margin: 4em auto;
  padding-left: 10px;
  padding-right: 10px;
  border-radius: 10%/50%;
  background: linear-gradient(to right, #11998E , #38EF7D);
  font-weight: 700;
}

.tooltip .tooltiptext {
  visibility: hidden;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
  }
<!DOCTYPE html>
<html>
<head></head>
  <body>
    <button onclick="myFunction()">Click to Create Divs</button>
  </body>
</html>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Change the tooltip's css to following:

.tooltip {
  position: relative;
  display: inline-block;
  width: auto;
  height: 1.6em;
  padding-left: 10px;
  padding-right: 10px;
  border-radius: 10%/50%;
  background: linear-gradient(to right, #11998E , #38EF7D);
  font-weight: 700;
}

i.e. remove "margin: 4em auto;". Due to margin, the actual height of the box is getting increased and creating the gap.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda