javascript - Find the width of a left floated list and apply to wrapper div to center it using css - jQuery? -


I want a ul center in a div with the left column of the liquid layout. To do this, I need to set the width of a div, which I used to wrap UL. Note: The list item (and content) is taken from the database using PHP.

I am interested in your suggestions that this is how to use jquery.

Consider the markup given below:

  & lt; Div id = "wrapper" & gt; & Lt; Div id = "left-column" & gt; & Lt; Div id = "list-wrap" & gt; & Lt; Ul & gt; & Lt; Li & gt; Dynamic content 1 & lt; / Li & gt; & Lt; Li & gt; Dynamic content 2 & lt; / Li & gt; & Lt; Li & gt; Dynamic content 3 & lt; / Li & gt; & Lt; Li & gt; Dynamic content 4 & lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Div & gt; & Lt ;! - / catalog-sheet - & gt; & Lt; / Div & gt; & Lt ;! - / left column - & gt; & Lt; Div id = "right-column" & gt; Content & lt; / Div & gt; & Lt ;! - / right-column - & gt; & Lt; Div style = "clear: both;" & Gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt ;! - / Cover - & gt;  

Use of this CSS:

  #wrapper {} # left column {float: left; Width: 50%; } # Right-column {float: true; Width: 50%; } #list-wrap {margin: 0 auto 0 auto; Padding: 40px; } #list-wrap_l {list-style-type: none; } #list-wrapped ul li (float: left: width 160px; height: 160px; margin: 20px;}  

I'm not very clever when it comes to javascript, but I am thinking that the solution will be implemented as such:

  1. Find the width # Useable content area to be left-column.
  2. Determine how many Fit in width (# list-keeping, margin and padding in mind).
  3. Round around 200px (160p X width + 2x20px margin)?
  4. Apply width to # list-wrap.

Here's something I used to do before Some of the criteria to get started are:

  var menuWidth = 0; $ (". Menu> ul> 
  • A). (Function (i ) {MenuWidth + = $ (this) .Utwaid (true);}) $ ("menu") .css ("width", menuUttp;) Thanks in advance for your help,

    Niels

  • Comments

    Popular posts from this blog

    oracle - The fastest way to check if some records in a database table? -

    php - multilevel menu with multilevel array -

    jQuery UI: Datepicker month format -