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 9039147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:39:47+00:00 2026-06-16T09:39:47+00:00

I want to vertically align text both when the text fits in one line

  • 0

I want to vertically align text both when the text fits in one line AND when the text fits in two lines. There’s a jsFiddle here.

enter image description here

Suppose my HTML looks like this:

<div class="Container">
   <div class="SomeClass">test text</div>
   <div class="SomeClass">some very very long text</div>  // this text is cut
</div>​

And that my CSS looks like this:

.Container{
    padding:3px 0px 6px 0px;
    height:30px;
    margin:30px 30px;}

.SomeClass{
    height:30px;
    float:left;
    width:100px;
    overflow:hidden;
    border:1px solid black;
    text-align:center;
    font-family:"Trebuchet MS";
    font-weight:bold;
    font-size:13px;
    line-height:28px;}​

At the moment, I’m using the line-height property: I set it to the height of the container, and that vertically aligns the text. The problem is that when the text fits in 2 lines, this doesn’t work anymore. Note that the .Container items must be of a certain height/width AND be left with overflow:hidden;

Let me know if you have some suggestions.

Thanks.

  • 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-06-16T09:39:49+00:00Added an answer on June 16, 2026 at 9:39 am

    First of all I didn’t understood this

    Note that the .Container items must be of a certain height AND be left
    with overflow:hidden;

    If you are giving a fixed height than I am sure it won’t fit 2 lines in there…

    And about the answer, you can use display: table-cell, use vertical-align: middle; and remove float: left; from .SomeClass

    Demo

    CSS (Ofcourse you can play with heights)

    .Container{
        padding: 3px 0px 6px 0px;
        margin:30px 30px;
        height: 200px;
    }
    
    .SomeClass{
        width:100px;
        height: 200px;
        border:1px solid black;
        text-align:center;
        font-family: "Trebuchet MS";
        font-weight: bold;
        font-size: 13px;
        display: table-cell;
        vertical-align: middle;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this html code, i want to align vertically the checbox in it's
I want to vertically align the text in select box. I tried using select{
Hell all: the below is the html code, I want to vertically align every
I want to vertically middle align text in a div that has height in
i want to vertically align the second table to the top of the div.
I want to split a series of divs vertically: My HTML might look like
I want my JTextArea to resize itself (expand vertically) when the last line (that
I have some divs floating inside another one and I want to align them
Possible Duplicate: How do I vertically align text next to an image with CSS?
I am using CarouFredSel as my carousel and I want to visually vertically align

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.