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

280
Views
How do I put the text to center of the div?

I just made this dropdown, but I have a problem.

When I resize the div/h4, the text goes to the top. I tried fixing this with text-align: center; but it did nothing.

Here's an image of what I'm trying to do:

Imgur image

Here's the css for it:


#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;}

And the HTML part of it, if you need it:

<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

Easiest solution is to use line-height on your h4 to center the text.

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

    // Other styling
}

enter image description here

about 4 years ago · Juan Pablo Isaza Report

0

You can center it vertically and horizontally by doing:

.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!