帝国CMS编辑器上传图片的时候默认会添加图片的宽高到链接样式中,这种情况图片在网站中显示就无法进行自适应,很容易撑破容器,造成不好的效果,如下图所示:
那么有没有去除上传图片默认显示宽和高的方法?当然,而且IT技术网提供了不止一种:
第1种,直接在添加图片时过滤(推荐)
考虑到帝国cms使用后台以及前台的投稿,需要同时找到以下文件进行修改:
/e/admin/ecmseditor/infoeditor/plugins/image/dialogs/image.js【后台修改路径】
/e/data/ecmseditor/infoeditor/plugins/image/dialogs/image.js【前台修改路径】
打开上面路径的文件,搜索下面的代码
this.imageElement.getAttribute("style") || this.imageElement.removeAttribute("style");
修改为以下代码
this.imageElement.setAttribute("style")&&this.imageElement.removeAttribute("style");
这样的话就移除了所有的style样式,直接使用CSS就可以了
第2种方法是在单独模板页面里过滤
PC版
<?
$xstyle=$r[newstext];
$xstyle=preg_replace('/style=.+?['|"]/i','',$xstyle);
echo $xstyle;
?>
手机版
<?
$xstyle=DoWapRepNewstext($r[newstext]);
$xstyle=preg_replace('/style=.+?['|"]/i','',$xstyle);
echo $xstyle;
?>
第3种,在全站模板的CSS里修改
<link href="[!--news.url--]skin/default/css/style.css" rel="stylesheet" type="text/css" />
在CSS里将img的代码改成这么
content img {
max-width: 600px;width:expression(this.width > 600 ? "600px":this.width);
/*如果图片大小超过600则自动按比例缩小到600*/
vertical-align:bottom;border:none;/*上半句是图片下沉,后面是无边框。常用*/
}