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

The Archive Base Latest Questions

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

I want to have a setup like this: <div id=block> <div class=btn>2</div> <div class=btn>1235e</div>

  • 0

I want to have a setup like this:

<div id="block">
<div class="btn">2</div>
<div class="btn">1235e</div>
<div class="btn">really long one</div>
</div>

jsfiddle: http://jsfiddle.net/cutcopypaste/3uu5Q/

Where the btns and block div get their width based on the content. Just like it appears in the fiddle, except that the width of the btns are based on their text rather than their container

I cannot use a table because I need to be able to apply styling to get vastly different appearance, so I need the html markup to stay basically the same. If it’s absolutely necessary I could apply some js.

I tried a couple different ways of displaying, but not sure how to acheive this. I don’t wish to hard-code any widths as the content will be changing, and I need it to work in older versions of IE (though I can use libraries like IE9.js).

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

    Here’s an example of how the #block will be sized to be as wide as its longest button:

    #block {
      float: left;
    }  
    
    .btn {
      float: left;
      clear: both; 
    }
    

    The floated elements will expand only to their content’s width. It’s assuming you want each button on its own line.

    If you want the buttons to flow together, remove the clear:both from the .btn rule. However if you do want them all on one line you’ll have to be aware of float drop. This will happen if the widths of all your buttons added together is greater than the available width. In this case, the rightmost button will drop down below the other buttons.

    Update: based on OP’s comment, here’s the CSS for a table cell style where #block and all .btn elements expand to the widest button’s width:

    #block {
      display: inline-block;
    }  
    
    .btn {
      display: block;
    }
    

    Along with an example.

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

Sidebar

Related Questions

I have a setup like this: <div class=item> <img src=.../> <span class=item-detail></span> <span class=item-detail></span>
Currently I have it setup like this. <ul id=slide> <li><img src=><div class=info>TEST1</div></li> <li><img src=><div
Ok I have a page setup that looks like this: <div class=parent>Content here</div> I
I have a header set up like this: <div id=header> <div class=container_16> <div class=grid_4><img
I have a div containing an event I want it to look like this
ok so basically I have a setup like this: <div id=tabs> <div id=tab_one> Something
I currently have a div whose css looks like this: .class { overflow:auto; resize:
I have a question about my layout. I have a setup something like this:
I have the following ul setup: <div id=sidebar> <ul id=themenu class=sf-menu sf-vertical> <li> <a
I currently have a page setup like this: PHP Variable Declarations HTML header, then

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.