停止CSS覆盖HTML宽度属性 [英] Stop CSS overriding HTML width attribute

查看:536
本文介绍了停止CSS覆盖HTML宽度属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些旧的内容包含表格,其宽度由HTML宽度属性指定,如:< table width =250> 。此属性正被CSS选择器 table 的规则覆盖。我可以停止这种覆盖,所以表格具有在HTML属性中指定的宽度(这不总是250像素,这只是一个例子)?我可以选择不应该使用选择器#column1 table 覆盖其宽度的表。

I have some old content containing tables with their width specified with an HTML width attribute like so: <table width="250">. This attribute is being overridden by a rule for the CSS selector table. Can I stop this overriding so the tables have the width specified in the HTML attributute (which is not always 250 pixels, this is just an example)? I can pick out the tables which shouldn't have their widths overridden with the selector #column1 table.

推荐答案

尝试这样:

#column1 table {
    width: auto;
}

这样你就知道了,css总是会覆盖旧的html内联属性。这使用所见即所得的编辑器时,通常是一个问题。

Just so you know, css will always override old html inline attributes. This is usually a problem when using a wysiwyg editor.

我解决了这个问题通过使用JavaScript和jQuery一个CMS所见即所得编辑器生成的旧的HTML。我遍历表并读取width和height属性,然后将其转换为inline css:

I solved this problem for the old html generated by a wysiwyg editor in a cms with javascript and jquery. I iterate over the table(s) and read the width and height attribute which I then convert to inline css:

var $table = $('#column1 table');
$table.css({
    "width" : $table.attr('width'),
    "height" : $table.attr('height')
});

这篇关于停止CSS覆盖HTML宽度属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆