简体   繁体   English

CKEditor表宽度和列宽度单位

[英]CKEditor Table Width and Column Width Units

I am currently testing CKEditor. 我目前正在测试CKEditor。

Especially the features of the table resize and table plugin. 特别是表格调整大小和表格插件的功能。

What I found out so far is that it seems to work sometimes with pt and sometimes with px. 到目前为止,我发现它似乎有时适用于pt,有时适用于px。

Is there a way I can change the behaviour to work always with percentage or some other kind of relative ratio instead of px or pt for column width? 有没有一种方法可以更改行为以始终使用百分比或某种其他相对比率(而不是列宽度的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>

My original post was on http://ckeditor.com/forums/CKEditor/CKEditor-Table-Width-and-Column-Width-Units . 我的原始帖子在http://ckeditor.com/forums/CKEditor/CKEditor-Table-Width-and-Column-Width-Units上 I decided to post it here because there was no activity on my question for two days. 我决定将其发布在这里,因为两天没有关于我的问题的活动。

I am looking for an easy way to adapt the table plugin in CKEditor either by configuration or programmatically via JavaScript to change the units from px eg to percentage or any other relative unit. 我正在寻找一种通过配置或通过JavaScript以编程方式通过CKEditor修改表插件的简便方法,以将px等单位更改为百分比或任何其他相对单位。

Update 更新

What I want is that the users sees in WYSIWYG a table is for example 100% width while editing. 我想要的是用户在所见即所得的表格中看到例如在编辑时宽度为100%。 When the user changes the column witdth they get changed in percentage and not in pixels. 当用户更改该列时,他们的更改百分比而不是像素。 Or the user makes the table smaller than 100 % total width. 或者用户使表格小于总宽度的100%。 Then the table gets changed in % not px. 然后,表格以%而不是px进行更改。

There does not appear to be a configuration setting to change this behavior, and editing the plugin itself is probably a bit of a headache. 似乎没有更改此行为的配置设置,并且编辑插件本身可能有点让人头疼。

You could simply give your table a percentage width and leave the rest as is. 您可以简单地为表格指定一个百分比宽度,其余部分保持不变。 Most modern browsers will treat/resize the cells in proportion. 大多数现代浏览器都会按比例处理/调整单元格的大小。 You could force this with jquery, or even with a simple CSS declaration. 您可以使用jquery甚至使用简单的CSS声明来强制执行此操作。 For example: $("table").width("100%"); 例如: $("table").width("100%"); , or table { width: 100% !important; } table { width: 100% !important; } table { width: 100% !important; } . table { width: 100% !important; }

Alternatively, you can use jquery to grab the current widths and change them to percentages, so for example something similar to this: 另外,您可以使用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> 

For some information on how you might add this using class names to specifically target CKEditor tables, see: https://stackoverflow.com/a/7980775/2126792 有关如何使用类名将其添加到专门针对CKEditor表的信息,请参见: https : //stackoverflow.com/a/7980775/2126792

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM