javascript - Equally space 3 divs inside a div using jQuery to make 4 equal sections -


i have table cell split 4 pixel perfect equal 'sections'.

this being done having 3 divs 1px wide (lines) these positioned using margin-left on top of div.

i'm doing in jquery need account space taken lines.

i have working fine.. of sections not same width. have taken account (i think) 3 lines removing 3px width of cell , dividing remaining 4 (4 sections...) cell gets bigger difference in section size.

this of course done in pure css have width of lines in % instead of px. having lines @ 0.5% not render well. prefer 1px.

i have feeling i'm missing simple?

here fiddle.

http://jsfiddle.net/sqag2/

code:

<style>         body {         padding: 30px;     }      .testtable {         margin: 0 auto;         border: 1px solid #f9f9f9;         width: 100%;     }      .testtable tr th {         padding: 10px;         border: 1px solid #c1c1c1;         box-sizing: border-box;     }      .testtable tr th:first-child {         width: 30%;     }      .testtable tr td {         background: #f9f9f9;         border: 1px solid #c1c1c1;         box-sizing:border-box;      }      .line {         position: relative;         background: #000;         width: 1px;         min-height: 20px;         float: left;         z-index: 9999;     } </style>  <table id="" cellspacing="0" cellpadding="0" class="testtable">     <thead>         <tr>             <th>col 1</th>             <th>col 2</th>             <th>col 3</th>             <th>col 4</th>             <th>col 5</th>         </tr>     </thead>     <tbody>         <tr>             <td>                 <div style="position: relative; width: 100%; overflow: hidden;">                      <div class="line"></div>                     <div class="line"></div>                     <div class="line"></div>                     <div class="block" style="width: 50%; min-height: 20px; background: green; z-index: 1; margin-left: 30%;"></div>                     <div class="" style="clear: both;"></div>                 </div>              </td>             <td>testing 2</td>             <td>testing 3</td>             <td>testing 4</td>             <td>testing 5</td>         </tr>     </tbody>  </table> 

<script>  var cellwidth,     linemargin;  // width of cell , remove 3px due 3 x 1px lines? cellwidth = $('.testtable tbody tr:first').find('td').width() - 3;  // divide 4 due 4 sections linemargin = (cellwidth / 4);  $('.line').css('margin-left', linemargin);  </script> 

assuming don't need ie8.

margin-left: calc(25% - 1px); 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -