Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6655489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:31:33+00:00 2026-05-26T01:31:33+00:00

Variations on this question have been asked many times. Vertical centering with CSS is

  • 0

Variations on this question have been asked many times. Vertical centering with CSS is a challenge.

I have a particular scenario, dealing with a list displayed horizontally. The markup is like this:

  <ul id='ul1' class='c'>
    <li><a href='javascript:void(0)'>Fribble Fromme</a></li>
    <li><a href='javascript:void(0)'>Fobble</a></li>
    <li><a href='javascript:void(0)'>Foo Fickle Pickle</a></li>
  </ul>

The style is like this:

  ul.c {
    height:52px;
    text-align:center;
  }
  ul li a {
    float:left;
    text-decoration:none;
    border: 1px solid Maroon;
    padding:2px 12px;
    background:#FFEF8A;
    line-height:1em;
    width:100px;
  }
  ul li a:hover {
    background: #CCC;
  }
  ul li {
    height:52px;
    display:inline-block;
  }

The resulting list looks like this:

enter image description here

But I want all the boxes to be the same height, and I want the text to be vertically centered in each box. I can set the box-height by adding a height style for the A elements. The result looks like this:

enter image description here

…which is close to what I want, but the vertical-centering isn’t happening.

I can set line-height for the text, as suggested in this post, to do the vertical centering. I can even pick different values of line-height for different A elements, if I know which of the elements will get multiple lines of text. But I don’t know which ones will require multiple lines.

How can I get it to center when some of the A elements have text that wraps?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:31:34+00:00Added an answer on May 26, 2026 at 1:31 am

    You could use display:table, etc. along with vertical-align:middle

    ul.c {
        text-align:center;
        display:table;
    }
    
    ul li {   
        float:left;    
    }
    
    ul li a {
        text-decoration:none;
        border: 1px solid Maroon;
        padding:2px 12px;
        background:#FFEF8A;
        width:100px;
        height:52px;
        display:table-cell;
        vertical-align:middle;
    }
    
    ul li a:hover {
        background: #CCC;
    }
    

    Example: http://jsfiddle.net/kf52n/2/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see variations of this question have been asked a couple of times, but
I know that variations on this question have been asked, but I've tried all
Variations on this question have been asked, but not this specifically. I have a
Variations of this question have been asked before, but it seems like the issue
The Disclaimer First of all, I know this question (or close variations) have been
First, I know this question has been asked several times before and that in
I know this question has been asked in several variations before, but my question
This is a variation on a question that has been asked here several times.
I know there have been plenty of variations on this question before, but none
I know, variations of this question had been asked before. But my case may

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.