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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:49:10+00:00 2026-05-13T12:49:10+00:00

I wish to center a ul in a div that is the left column

  • 0

I wish to center a ul in a div that is the left column of a liquid layout. To do so I need to set the width of a div that I’ve used to wrap the ul. Note: the list items (and content) are retrieved from a database using php.

I’m interested in your suggestions on how to do this using jquery.

Consider the below markup:

<div id="wrapper">

   <div id="left-column">
     <div id="list-wrap">
       <ul>
        <li>Dynamic content 1</li>
        <li>Dynamic content 2</li>
        <li>Dynamic content 3</li>
        <li>Dynamic content 4</li>
       </ul>
      </div><!--/list-wrap-->
   </div><!--/left-column-->

   <div id="right-column">
     Content
   </div><!--/right-column-->

   <div style="clear: both;"></div>

   </div><!--/wrapper-->

Using this css:

#wrapper {}
#left-column { float: left; width: 50%; }
#right-column { float: right; width: 50%; }
#list-wrap { margin: 0 auto 0 auto; padding: 40px; }
#list-wrap ul { list-style-type: none; }
#list-wrap ul li { float: left: width 160px; height: 160px; margin: 20px; }

I’m not too clever when it comes to javascript but I’m thinking the solution would entail something like this:

  1. Find the width of the usable content area of #left-column.
  2. Work out how many li’s would fit into that width (taking into account the margin and padding of #list-wrap).
  3. Round off the figure to nearest 200px (160px width + 2x20px margins)?
  4. Apply the width to #list-wrap.

Here is something I have used before that meets SOME of the criteria to get started:

   var menuWidth = 0;
   $(".menu > ul > li > a").each(function(i) {
     menuWidth += $(this).outerWidth(true);
     });
    $(".menu").css("width", menuWidth);

Thanks in advance for your help,

Niels

  • 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-13T12:49:10+00:00Added an answer on May 13, 2026 at 12:49 pm

    You dont need js to do a css job!

    consider this style:

    #wrapper {}
    #left-column { float: left; width: 50%; }
    #right-column { float: right; width: 50%; }
    #list-wrap { margin: 0 auto 0 auto; padding: 40px; }
    #list-wrap ul { list-style-type: none; text-align: center; }
    #list-wrap ul li { width: 160px; height: 160px; margin: 20px; display: inline-block; }
    

    Get rid of float: left; for the li items and add a display: inline-block;

    Finally, add text-align: center; to the UL to make them centered

    I hope this is what you were lookin for.

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

Sidebar

Related Questions

I wish to centre a wrapper div of fixed width (wrapper) inside another div
I wish HTML could do something semantically equivalent to this; <dl class=main-list> <definitionitem> <dt>Some
I wish I could figure this out. I need to produce a table with
I wish to iterate over a set but the contents of the set will
I'm looking to create a flexible width/height page layout with no window scrollbars! Any
I wish to center a widget in the middle of the browser window (horizontally
hi friends I wish to design my xml in table layout but, I am
I have three buttons in my Actvity inside Linear Layout. Here i wish all
I have an HTML code: <div id=first></div> I wish to use javascript (document.findElementById) to
I have a square div of fixed size and wish to place an arbitrary

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.