javascript
  • html
  • css
  • 2016-07-25 48 views 0 likes 
    0

    這裏是我的表結構表格的佈局:固定的CSS沒有給定列的寬度正常工作

    <table id="recordingsTable" style="width:900px" class="tablesorter fixed_table"> 
    </table> 
    

    CSS:

    .fixed_table{ 
        table-layout: fixed; 
    } 
    

    填充表從JS:

    str = '' 
    str += '<thead>' 
    str += '<tr>' + 
        '<th style="width:150px;text-align:left !important;border-left:0;">Col 1</th>' + 
        '<th style="width:150px;text-align:center !important">Col 2</th>' + 
        '<th style="width:300px;text-align: center !important;">Col 3</th>' + 
        '<th style="width:100px;text-align: center !important;">Col 4</th>' + 
        '<th style="width:100px;text-align: center !important;">Col 5</th>' + 
        '<th style="width:100px;text-align: center !important;">Col 6</th>' + 
        '</tr>' + 
        '</thead><tbody style="border-bottom: 1px solid #dddddd;">'; 
    
    
        for(i=0; i < recording_object.length; i++) { 
         str += '<tr>'; 
         str += '<td style="text-align:left !important; padding-left:8px;border-left:0;">' 
         str += recording_object[i].text 
         str += '</td>' 
         str += '<td class="s3_file_path">' + recording_object[i].path + '</td>' 
         str += '<td class="s3_file_name" style="font-size:11px;">' + recording_object[i].file_name + '</td>' 
         str += '<td>' + recording_object[i].number + '</td>' 
         str += '<td>'; 
         str += '<button id="' + recording_object[i].id + '" onclick="dup_dialog(this)" type="button" data-toggle="modal" ' + 
          'data-target="#upload-all-modal" disabled="disabled" class="btn btn-primary btn-xs">Duplicate</button>' + 
          '</td>' 
         str += "<td>"; 
         str += '<button id="' + recording_object[i].id + '" class="btn btn-primary btn-xs" data-toggle="modal" ' + 
          'disabled="disabled" data-target="#association">Association</button>' 
         str += '</td></tr>' 
        } 
        str += '</tbody>' 
    

    但它沒有顯示js中定義的表格列的寬度,當我更改任何列寬度時它不會在視圖中更改;即使當我通過檢查元素

    來改變它時,它似乎表格佈局不能正常工作,因爲它應該給定每個列寬度。誰能幫忙?

    下面是表截圖: enter image description here

    +0

    你能張貼呈現的HTML請 – Pete

    +0

    加入截圖 –

    回答

    0

    我看到的是thead一個問題。你忘記打開它。我把一些隨機data.I也去掉了墊襯在cells.The寬度完全一樣你在javascript中指定它。檢查小提琴。

    https://jsfiddle.net/ks3mj4ec/4/

    +0

    THEAD加入我錯過了這裏。我會更新我的問題 –

    +0

    的寬度是完全一樣的你在fiddle.Col 3中指定它的寬度爲300px,Col 5 100px等。所以你必須有其他的css規則也會導致這個問題,因爲對於我來說按照預期工作。 。 –

    相關問題