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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:42:24+00:00 2026-06-14T08:42:24+00:00

I have an image and some text inside a div and I’d like to

  • 0

I have an image and some text inside a div and I’d like to put the image and the text in the vertical center of the div using CSS. The problem is that I don’t know how many lines of text I will have but the text and the image must be ALWAYS in the middle. For example, when there’s only one line of text the div should look like this:

####################################
#  _______                         #
# |       |                        #
# |       |                        #
# | IMAGE |    text text text      #
# |       |                        #
# |_______|                        #
#                                  #
####################################

If eventually I have more lines or the height of text is larger than the height of the image then the image should be aligned, just like this:

####################################
#                                  #
#              text text text      #
#  _______     text text text      #
# |       |    text text text      #
# |       |    text text text      #
# | IMAGE |    text text text      #
# |       |    text text text      #
# |_______|    text text text      #
#              text text text      #
#              text text text      #
#                                  #
####################################

I’m in trouble to get this effect, is there any way without using javascript to do this?

Obs. The parent div of the div I’m referring to have position:relative so there’s another problem.

  • 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-14T08:42:25+00:00Added an answer on June 14, 2026 at 8:42 am

    Give both the image and the text a vertical-align: middle – the text needs to be contained in an element that is also display: inline. So markup like this:

    <div>
      <span><img src="blah.jpg" /></span>
      <span>text text text</span>
    </div>
    
    div {
      display: table;
    }
    
    img {
      vertical-align: middle;
      display: table-cell;
    }
    span {
      vertical-align: middle;
      display: table-cell;
    }
    

    should work. Here’s a jsfiddle to demonstrate (edited fiddle to show everything is vertically aligned within a container as well.)

    EDIT: to get the behavior you want, I recommend using additional display properties – table for the container and table-cell for the contained elements. Fiddle link has been updated with the changes.

    EDIT: the only way I could think of to get it to work was to wrap the image in another inline container, in this case a span. I’ve updated the fiddle to demonstrate.

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

Sidebar

Related Questions

I have a block with some text and image inside. Like: <div>I just posted
I have an image and some text. I want to center both of them
We have an url like http://site.s3.amazonaws.com/images/some image @name.jpg inside $string What I'm trying to
I have an image and a hyperlink inside a div, but for some reason,
I have some dynamic text contained in a div that is set to whatever
I have a div contain the image inside it like this : <div class=gallery
I have some HTML code with a dialog inside, like this: <center> <a href=#add_auto
I have a custom UITableViewCell which has an image & and some text. When
I have a script which collects an image, link and some text content from
I have some 10 buttons with image-text and hover states for each. What I

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.