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

  • Home
  • SEARCH
  • 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 430221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:51:14+00:00 2026-05-12T19:51:14+00:00

OK so what would happen if I have 2 divs (one containing text, the

  • 0

OK so what would happen if I have 2 divs (one containing text, the other an image). The image always has a static width but the text varies. hence making its containing div variable.

I can make it work for all other browsers (except IE6 and IE7) by using CSS display:table. IE6 and 7 don’t have that so I can’t find a workable solution to center them all.

… so you know what I’m talking about…

.container{text-align:center; width:100%}

.container .centered{display:table; margin:0 auto}

    <div class="container">
        <div class="centered">
            <div id="text">varying length text</div>
            <div id="image">IMAGE</div>
        </div>
    </div>
  • 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-12T19:51:14+00:00Added an answer on May 12, 2026 at 7:51 pm

    Quite apart from the lack of IE support, setting display: table as you have without its children using display: table-row/table-cell results in undefined behaviour. It doesn’t make sense to put block elements directly inside a table element and the browser might do anything at all.

    What you are trying to do is get shrink-to-fit width behaviour without using float, which is a normal way of getting shrink-width but requires that the block in question goes to the left or right not centre. Probably a better way of saying that would be to use an inline-block:

    .centered { text-align: center; }
    .centered span { display: inline-block; border: dotted red 1px; }
    
    <div class="centered">
        <span id="text">varying length text</span>
    </div>
    <div class="centered">
        <span id="image">IMAGE</span>
    </div>
    

    (You have to use a naturally-inline element like span to make it work under IE<8; div would fail. There is also -moz-inline-box if you need to target Firefox 2.)

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

Sidebar

Related Questions

Would anyone happen to know how to convert type LPTSTR to char * in
Would it be possible to show an image in full screen mode using silverlight.
Would the following SQL remove also the index - or does it have to
A quick question. I have a series of DIVs with the following classes .level1
I would like Visual Studio to break when a handled exception happens (i.e. I
Would it not make sense to support a set of languages (Java, Python, Ruby,
Would it be possible to print Hello twice using single condition ? if condition
Would having a nice little feature that makes it quicker to write code like
Would it be wwwroot, C, the root virtual directory where the assets are hosted,
Would a C++ CLI compiler be able to compile some large sets of C++

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.