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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:19:17+00:00 2026-06-10T10:19:17+00:00

How do I verically center the content of floating div (which height I don’t

  • 0

How do I verically center the content of floating div (which height I don’t know)?

There is very simple HTML and CSS (see this fiddle: http://jsfiddle.net/DeH6E/1/)

<div class="floating">
    This should be in the middle
</div>
​
.floating {
    height: 100px;
    float: left;
    border: 1px solid red;
    vertical-align: middle;
}   ​

How do I make the sentence “This should be in the middle” appear really in the middle (vertically centered)? vertical-align: middle does not seem to work. I have tried display: table-cell and it didn’t work either. What’s the best way to solve this issue? I’d like to avoid inserting any other HTML tags, do it just via CSS.

(Just to make it clear: I don’t know the actual height of the container, 100px is just for the example)

EDIT: I’d like you to understand me, so… Always when I design web page, I follow the rule that HTML holds the content and CSS is responsible for the visual style. I never mix them up together or use one just to enable the other. In this case, I want to stick with this rule too. I don’t want to insert HTML element just for the CSS.

  • 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-10T10:19:18+00:00Added an answer on June 10, 2026 at 10:19 am

    The others are right, you need to nest two DOM elements which gives you more options controlling the centering. Here’s the code:

    .floating {
      display: table;
      float: right;
      height: 200px;
      width: 400px;
      border: 1px solid red;
    }
    .floating p {
      display: table-cell; 
      vertical-align: middle; 
      text-align: center;
    }
    <div class="floating">
        <p>This is the proper way that validates and breaks across multiple
        lines, if the text is longer than just a few words and still
        should be vertically centered. Here, it's also horizontally
        centered for added joy.</p>
    </div>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this CSS to vertically center a sprite: #content { width:750px; height:950px; position:absolute;
I'm trying to vertically center a div in the viewable area on a very
I have a very simple HTML. Due to some limitations, I cannot modify the
I have a <div id=wrapper> container in which my whole site content will be
Ok, so I am trying to center a div with dynamic content ( both
I would like to vertically center my main content div. I am open to
I'm trying to vertically and horizontally center content of an unknown height in a
I'm trying to horizontally and vertically center a modal window inside a div. I
Possible Duplicate: How to center div horizontally and vertically I need to put image
How do I center align the image to vertically and horizontally to the div.

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.