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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:47:39+00:00 2026-05-14T23:47:39+00:00

Is there a way to perform a vertical centering of a variable-sized multi-line content

  • 0

Is there a way to perform a vertical centering of a variable-sized multi-line content within a fixed-size div, with hidden overflow?

The aim would be to reproduce what you can see in Excel cells: when the content fits the container, it should be vertically centered, when it is larger, the parts that overflow should be hidden (and the content still vertically aligned), like in an Excel cell whose neighbours aren’t empty.

I know how to vertically center using CSS, I know how to hide overflow when the content isn’t vertically centered, but I’ve no idea how to do both at the same time… Is Javascript the only answer?

The trick is that CSS positioning approaches don’t work with variable-sized content (my content is dynamic text), and when you use display:table-cell, it effectively disables CSS overflow control (and the container grows to accomodate the content).

  • 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-14T23:47:40+00:00Added an answer on May 14, 2026 at 11:47 pm

    This should make all the cells 65px high, and make the cells’ text show up in the middle. When it’s too much text, the text disappears bellow.
    I believe it’s what you want?

    CSS:

    .row {
      border: solid 1px blue;
      display: block;
      height: 65px; /* arbitrary value */
      overflow: hidden;
      line-height: 65px; /* same as height */
    }
    
    .cell {
      border: solid 1px #CCCCCC;
      display: inline-block;
      vertical-align: middle;
      height: 100%;
    }
    
    .cellContents {
      display: inline-block;
      max-height: 100%;/*would 100%; work?*/
      width: 100px; /* arbitrary value */
      overflow: hidden;
      border: solid 1px red; /* just to see that it's centered */
      line-height: 100%; /* so it does not inherit the huge line-height, and we get more than one line of text per cell */
    }
    

    HTML:

    <div class="table">
        <div class="row">
            <span class="cell"><span class="cellContents">cell 1 1</span></span>
            <span class="cell"><span class="cellContents">cell 1 2</span></span>
            <span class="cell"><span class="cellContents">cell 1 3</span></span>
        </div>
    
        <div class="row">
            <span class="cell"><span class="cellContents">cell 2 1</span></span>
            <span class="cell"><span class="cellContents">This should make all the cells 65px high, and make the cells' text show up in the middle. When it's too much text, the text disappears bellow.</span></span>
            <span class="cell"><span class="cellContents">cell 2 3</span></span>
            <span class="cell"><span class="cellContents">cell 2 4</span></span>
        </div>
    </div>
    

    You can try it on JSFiddle.

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

Sidebar

Related Questions

Is there a way to perform an HTTP GET request within a Visual Basic
Is there a way to perform a FULLTEXT search which returns literals found within
What is the right way to perform some static finallization? There is no static
Question: Is there an easy way (library function) to perform a bitwise AND or
Is there a way to perform a top (Take) linq query using percentage? The
Is there any way to perform SQL Like Queries or Filtering on Java Data
Is there a way to perform updates on a PIVOTed table in SQL Server
Is there any way to perform a merge with subversion 1.6 which would preserve
Is there a way to perform the following in a non-recursive fashion: my_list =
Is there any way to perform Fluent EF Mapping like Fluent NHibernate for NHibernate

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.