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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:51:42+00:00 2026-06-16T00:51:42+00:00

So, I have a list of inline-block list items. They all vary in width,

  • 0

So, I have a list of inline-block list items. They all vary in width, but are always on the same line. The number of list items may also vary, so I can not predict the width of the list as a whole. The list should always be centered in its parent container, but when the width exceeds 100%, it should gain a horizontal scroll rather than extending over two lines.

Now, as far as I understand, if I set the width to auto, it is actually set to shrink-to-fit – essentially meaning max-width: 100%;, which is not what I want.

Is there a way for me to achieve this reliably with CSS alone?

Markup

<div>
  <ul>
    <li>Banana</li>
    <li>Krypton</li>
    <li>Molten boron</li>
  </ul>
</div>

CSS

div {
  overflow-x: auto;
  width: 500px;
}
ul {
   max-width: 5000px; /* Doesn't override */
   width: auto; /* Calculated to 500px or less */
}
li { display: inline-block; }

It should be noted that this is a responsive layout, so the width of the container is not exactly fixed, but I’m not afraid of manual labour.

My JS Fiddle: http://jsfiddle.net/TheNix/gdRaB/

My question is similar to CSS dynamic width larger than 100% except my child elements are not floated, ergo still in the flow (I have control over this).

Regarding width: auto; in the spec: http://www.w3.org/TR/CSS2/visudet.html#inline-replaced-width

  • 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-16T00:51:43+00:00Added an answer on June 16, 2026 at 12:51 am

    Unless I misunderstood your question, you can simply add white-space: nowrap; to your ul (fiddle). Then you’ll get the desired horizontal scrollbar upon overflow.

    [Edit]: and text-align: center; to your div (fiddle)

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

Sidebar

Related Questions

Possible Duplicate: A Space between Inline-Block List Items I have a JSFiddle demo of
The inline-block list items have constant spaces between them by default if the margin
I have list items, with a span, set to inline-block and floated right. This
I have an unordered list: <ul class=list_arrow2> <li> <span style=display: inline-block; width: 150px; font-weight:
I have an unordered list whose list items are displaying inline. However, its layout
I have some list items with anchor tags, that are set to display block
I have a list with five items which is displayed inline. The text in
Possible Duplicate: Unwanted margin in inline-block list items How to remove Invisible space from
All, I have list items which have a background set to them (RGBA value).
Say I have textboxes, dropdownlists and submit buttons. They are all inline-elements. Which means

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.