簡體   English   中英

CKEditor表寬度和列寬度單位

[英]CKEditor Table Width and Column Width Units

我目前正在測試CKEditor。

特別是表格調整大小和表格插件的功能。

到目前為止,我發現它似乎有時適用於pt,有時適用於px。

有沒有一種方法可以更改行為以始終使用百分比或某種其他相對比率(而不是列寬度的px或pt)工作?

<table border="1" cellpadding="1" cellspacing="1" style="width:1340px">
    <thead>
        <tr>
            <th scope="col" style="width:386px">1</th>
            <th scope="col" style="width:953px">
            <p>2</p>
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td style="width:386px">3</td>
            <td style="width:953px">4</td>
        </tr>
    </tbody>
</table>

我的原始帖子在http://ckeditor.com/forums/CKEditor/CKEditor-Table-Width-and-Column-Width-Units上 我決定將其發布在這里,因為兩天沒有關於我的問題的活動。

我正在尋找一種通過配置或通過JavaScript以編程方式通過CKEditor修改表插件的簡便方法,以將px等單位更改為百分比或任何其他相對單位。

更新

我想要的是用戶在所見即所得的表格中看到例如在編輯時寬度為100%。 當用戶更改該列時,他們的更改百分比而不是像素。 或者用戶使表格小於總寬度的100%。 然后,表格以%而不是px進行更改。

似乎沒有更改此行為的配置設置,並且編輯插件本身可能有點讓人頭疼。

您可以簡單地為表格指定一個百分比寬度,其余部分保持不變。 大多數現代瀏覽器都會按比例處理/調整單元格的大小。 您可以使用jquery甚至使用簡單的CSS聲明來強制執行此操作。 例如: $("table").width("100%"); table { width: 100% !important; } table { width: 100% !important; }

另外,您可以使用jquery來獲取當前寬度並將其更改為百分比,例如,類似於以下內容:

var tableWidth = $("table").width();
$("table tr").children().each(function( index ) {
    $(this).width(Math.round(100 * $(this).width() / tableWidth)+"%");
});

 $("table").width("100%"); var tableWidth = $("table").width(); $("table tr").children().each(function( index ) { $(this).width(Math.round(100 * $(this).width() / tableWidth)+"%"); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table border="1" cellpadding="1" cellspacing="1" style="width:1340px"> <thead> <tr> <th scope="col" style="width:386px">1</th> <th scope="col" style="width:953px"> <p>2</p> </th> </tr> </thead> <tbody> <tr> <td style="width:386px">3</td> <td style="width:953px">4</td> </tr> </tbody> </table> 

有關如何使用類名將其添加到專門針對CKEditor表的信息,請參見: https : //stackoverflow.com/a/7980775/2126792

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM