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

288
Views
How to center div below other element, not parent div?

Here's an image showing what I'm trying to achieve:

enter image description here

As you can see, I'm trying to get the profile options dropdown to be centered below the profile button. The current way I have it set up is to have the dropdown menu have position: absolute, and then use a margin-left: -3% to actually "center" it, but I feel like there should be a more reliable way to actually center it that isn't dependent on a hardcoded percentage value. Below is the relevant code:

index.php:

<div id="navTools">
    <button id="navProfile"><img src="./imgs/profile.svg" alt="Profile"/></button>
    <div id="profileDropdown">
        <a href="#example">Account Information</a>
        <a href="#example">Orders & Returns</a>
        <a href="./logout.php">Logout</a>
    </div>
    <a id="navCart" href="cart.php"><img src="./imgs/cart.svg" alt="Cart"/></a>
</div>

styles.css

#profileDropdown {
  display: none;
  background: #1d1d1d;
  position: fixed;
  margin-left: -3%;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Wrap profile button and profile dropdown in a div. Give that div position: relative and set position: absolute for the dropdown. If you want it to appear at the bottom, set bottom: 0. If you want to center it vertically, set left: 50%, transform: translateX(-50%).

<div id="navTools">
<div class="dropdown-wrapper">
    <button id="navProfile"><img src="./imgs/profile.svg" alt="Profile"/></button>
    <div id="profileDropdown">
        <a href="#example">Account Information</a>
        <a href="#example">Orders & Returns</a>
        <a href="./logout.php">Logout</a>
    </div>
</div>
<a id="navCart" href="cart.php"><img src="./imgs/cart.svg" alt="Cart"/></a>
.dropdown-wrapper {
    position: relative;
}

#profileDropdown {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}
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!