Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

279
Views
¿Cómo coloco el texto en el centro del div?

Acabo de hacer este menú desplegable, pero tengo un problema.

Cuando cambio el tamaño de div/h4, el texto va a la parte superior. Intenté arreglar esto con text-align: center; pero no hizo nada.

Aquí hay una imagen de lo que estoy tratando de hacer:

imagen de Imgur

Aquí está el css para ello:

 #alue_search { box-sizing: border-box; background-image: url('https://cbot.me/images/alue_icon.png'); background-position: 14px 12px; background-repeat: no-repeat; font-size: 16px; padding: 14px 20px 12px 45px; border: none; /*border-bottom: 3px solid #ddd;*/ color: #353535; border-radius: 5px 5px 0px 0px; } #alue_search:focus { outline: none; } .dropdown { display: inline-block; position: relative; background-color: #f6f6f6; min-width: 230px; z-index: 1; border-radius: 5px; border: 3px solid #ddd; } .dropdown-content { position: relative; z-index: 1; } .dropdown-content h4 { height: 35px; background-color: #fff; border: none; border-radius: 5px; color: #353535; transition: all 0.3s ease-in-out; display: none; } .dropdown-content h4:hover { background-color: #ddd; cursor: pointer; } .dropdown-content div { height: auto; } .show {display:block;}

Y la parte HTML, si la necesitas:

 <div class="dropdown"> <div id="myDropdown" class="dropdown-content"> <input type="text" placeholder="Etsi alue" id="alue_search" onkeyup="filterFunction()"> <div onclick="select('Helsinki')"><h4>Helsinki</h4></div> <div onclick="select('Jyväskylä')"><h4>Jyväskylä</h4></div> <div onclick="select('Kuopio')"><h4>Kuopio</h4></div> </div> </div>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

La solución más fácil es usar line-height en su h4 para centrar el texto.

 .dropdown-content h4 { line-height: 35px; // Vertical center text-align: center; // Horizontal center // Other styling }

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza Report

0

Puedes centrarlo vertical y horizontalmente haciendo:

 .dropdown-content h4 { height: 35px; ... text-align:center; line-height:35px; }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!