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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:56:49+00:00 2026-05-14T02:56:49+00:00

I have an outer div that is 800px wide. I have an inner div

  • 0

I have an outer div that is 800px wide. I have an inner div that could be anywhere from 200 to 600px wide.

I know how to center the inner div within the outer one if I set the inner one to have a specific width, but how do I center it since its a variable width?

Is there a way to set the div to only be the width of the elements inside of it, rather than having it expand to fill its containing 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-14T02:56:49+00:00Added an answer on May 14, 2026 at 2:56 am

    Floating, display:inline-block, or absolute positioning will shrink-wrap a div. Of those, display:inline-block would be the easiest to center with a simple text-align:center. If you have to support crappy browsers (I’m sure you do), check this out.

    Assuming you aren’t supporting FF2 still, you can actually do away with most of the hacks, and still support older IE’s by making the inner div a span instead. display:inline-block works on older IE as long as the element was originally an inline element.

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

Sidebar

Related Questions

I have an outer div, and inside of that, I have an inner div
I have outer div and inner div. I need to place inner div at
I have the following html code: <div class=outer ui-draggable style=position: relative;> <div class=inner>Foo bar</div>
I'm creating a horizontal menu bar. There is an outer div that contains inner
I have a div ( .outer - the viewport) with fixed height that contains
I have a div that contains another div. If the user clicks the inner
I have two div like: <div class=outer> <div class=inner></div> </div> then I give them
I have two divs, one inner and one outer, but the inner div is
I have the markup like that: <div class=outer> <a class=btn> <img src=btnImg.jpg /> </a>
It seems that with markup like http://jsfiddle.net/nwekR/ <div id=container> Outer Div <div id=inner>Inner Div</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.